我希望在VBA中编写代码,以便根据其缩进级别将数据分类到相邻的列中。我设法根据单元格中开始的空格数编写了可以正常工作的代码,但是我似乎找不到基于缩进来移动它们的方法。这是我到目前为止编写的代码:
Sub Movecellindent()
Dim row As Long
For row = 3 To 3000
'cells that begin with 15 spaces are moved to column D
If Range("A" & row).Value Like " *" Then
Range("D" & row).Value = Range("A" & row).Value
Range("A" & row).Value = ""
End If
Next
For row = 3 To 3000
'cells beginning with 12 spaces are moved to column C
If Range("A" & row).Value Like " *" Then
Range("C" & row).Value = Range("A" & row).Value
Range("A" & row).Value = ""
End If
Next
For row = 3 To 3000
'cells beginning with 10 spaces are moved to column B
If Range("A" & row).Value Like " *" Then
Range("B" & row).Value = Range("A" & row).Value
Range("A" & row).Value = ""
End If
Next
我希望代码执行相同的操作,但分别具有3个,2个和1个缩进。
谢谢!