2011-01-27 106 views

回答

2
Sub MoveRight() 

    Dim rFound As Range 
    Dim lFirstCol As Long 
    Dim rSearch As Range 

    Const sSEARCH As String = "A" 

    Set rSearch = Sheet1.Cells 
    'Find the first instance in the right most column 
    Set rFound = rSearch.Find(sSEARCH, rSearch.Cells(1), xlValues, xlWhole, xlByColumns, xlPrevious, True) 

    'If a cell was found 
    If Not rFound Is Nothing Then 
     'Record the column so we know when to stop 
     lFirstCol = rFound.Column 

     'loop through all the found cells 
     Do 
      rFound.Offset(0, 1).Value = rFound.Value 
      rFound.ClearContents 
      Set rFound = rSearch.FindPrevious(rFound) 
     'stop when it wraps back around and finds the first 
     'instance that you moved one cell to the right 
     Loop Until rFound.Column > lFirstCol 
    End If 

End Sub 

确保在运行此宏之前保存文件的备份。如果它没有做你想做的事,那就没有撤销。

+0

很好,谢谢。 – fairidox 2011-01-27 15:47:07