0
我想将所有与特定搜索字符串匹配的单元格移动到Excel 2011中的右侧,但我是一个完全的Excel noob。Excel宏将与表达式单元格匹配的单元格向右移动
例如,搜索字符串 “A”:
A A A _ _ B A A _
到:
_ A A A _ B _ A A
NOT:
_ A _ A _ B _ A
谢谢!
我想将所有与特定搜索字符串匹配的单元格移动到Excel 2011中的右侧,但我是一个完全的Excel noob。Excel宏将与表达式单元格匹配的单元格向右移动
例如,搜索字符串 “A”:
A A A _ _ B A A _
到:
_ A A A _ B _ A A
NOT:
_ A _ A _ B _ A
谢谢!
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
确保在运行此宏之前保存文件的备份。如果它没有做你想做的事,那就没有撤销。
很好,谢谢。 – fairidox 2011-01-27 15:47:07