Excel
行,我之间有空行。离。
答案 0 :(得分:0)
假设您的数据位于电子表格的A列(从单元格A1开始),并且您希望计算空格并删除行,如下所示:
Col A Col B Col A Col B
1 AAA AAA 2
2 BBB 1
3 CCC 0
4 BBB DDD 2
5 ---- Output ---> EEE
6 CCC
7 DDD
8
9
10 EEE
以下代码将实现这一结果:
Sub CountEmptyRows()
Dim lastRow As Long, rw As Long, count As Integer
lastRow = Range("A65536").End(xlUp).Row - 1
count = 0
For rw = lastRow To 1 Step -1
If IsEmpty(Cells(rw, 1)) Then //If cell is empty increment the count and delete the row
count = count + 1
Cells(rw, 1).EntireRow.Delete
Else
Cells(rw, 2) = count //Display emtpy row count and then reset counter
count = 0
End If
Next rw
End Sub