选择范围内包含 space 的单元格
Selecting cells that contain a space in a range
我试图从列中分离出包含 space 的单元格。我试过使用查找功能,但它似乎没有记录到 'record macro'.
我也在分离只包含数字的单元格,但使用 'find->go to special->Constants(numbers)->insert->shift cells' 对 'record macros'
效果很好
Example
查看此代码,了解如何设置要处理的 sheet 以及要处理的 sheet 的范围。如所写,它将在活动 sheet.
上处理范围 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
我试图从列中分离出包含 space 的单元格。我试过使用查找功能,但它似乎没有记录到 'record macro'.
我也在分离只包含数字的单元格,但使用 'find->go to special->Constants(numbers)->insert->shift cells' 对 'record macros'
效果很好Example
查看此代码,了解如何设置要处理的 sheet 以及要处理的 sheet 的范围。如所写,它将在活动 sheet.
上处理范围 A1:A10Sub 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