选择区域中包含空格的单元格



我正在尝试从列中分离出包含空格的单元格。我试过使用find函数,但它似乎没有记录到"记录宏"中。

我还分离出只包含数字的单元格,但使用'find->转到特别->常量(数字(->插入->移位单元格右侧与"记录宏"配合良好

示例

看看这段代码,了解如何设置要处理的工作表以及要处理工作表的范围。如所写,它将处理活动工作表上的范围A1:A10。

Sub move_cells_with_space()
Dim s As Worksheet
Dim range_to_process As Range
Dim cell As Range

'choose the sheet to work on
Set s = ActiveSheet ' use this for the actve sheet
'Set s = Worksheets("Sheet1") ' use this for a specific sheet

'choose the range to process
Set range_to_process = s.Range("a1:a10")

For Each cell In range_to_process
If InStr(1, cell.value, " ") > 0 Then
cell.Offset(0, 1).value = cell.value
cell.value = ""
End If
Next

End Sub

最新更新