我想对用空行分隔的数据集进行编号。我认为自动填充VBA将是我所需要的,但似乎找不到适合我要执行的操作的任何东西。我遇到的问题是数据会变化,并且每个序列中的行数不一定总是相同。鉴于此,我希望A列(计数)根据C列(姓)中的信息增加,并在有空行时重新开始,直到工作表末尾。我在下面给出了我要寻找的最终结果的示例。谢谢!
Count ID Last Name First Name
1 344969 Test Test
2 Test Test
3 344971 Test Test
4 Test Test
5 344973 Test Test
6 344974 Test Test
7 344975 Test Test
8 Test Test
(Blank Row)
1 Test 2 Test 3
2 200474 Test 2 Test 3
3 200475 Test 2 Test 3
4 200476 Test 2 Test 3
5 Test 2 Test 3
6 200478 Test 2 Test 3
7 200479 Test 2 Test 3
8 Test 2 Test 3
9 Test 2 Test 3
10 200482 Test 2 Test 3
(Blank Row)
1 195959 Test 5 Test 6
2 195960 Test 5 Test 6
3 195961 Test 5 Test 6
4 195962 Test 5 Test 6
5 195963 Test 5 Test 6
6 195964 Test 5 Test 6
7 195965 Test 5 Test 6
8 195966 Test 5 Test 6
9 195967 Test 5 Test 6
10 195968 Test 5 Test 6
我尝试过条件格式,但是没有运气。我还有其他几个宏,并且想添加一个执行此功能的宏。
答案 0 :(得分:1)
类似的方法可能对您有用:
Sub countSomething()
Dim ws As Worksheet: Set ws = ActiveWorkbook.Sheets("sheet name")
Dim lrow As Long: lrow = ws.Cells(Rows.Count, "B").End(xlUp).Row 'get last row at the column that will always be populated
Dim R As Long, X As Long: X = 1
For R = 2 To lrow
If WorksheetFunction.CountA(ws.Cells(R, 1).Resize(1, 4)) = 0 Then 'empty row
X = 1
Else
ws.Cells(R, 1) = X
X = X + 1
End If
Next R
End Sub