我试图整理需要转换为其他格式的清单。 只是想知道,有没有办法找到一组空白单元并使用VBA删除它们?
文件如下所示:
name
address
address
region
-blank line-
-blank line-
-blank line-
Name
Address
Address
Region
-blank line etc
我想要的是删除分组的空白单元格。我遇到的问题有时其中一个地址栏是空白的(一个空白行),所以我不能只使用Go to > Special...
我想要的是,如果我能弄清楚如何使VBA在列中运行,在一个上面拾取一组3个或更多空白单元格,并删除整个行。 这可能吗?
干杯,奈杰尔。
答案 0 :(得分:0)
您可以随时执行以下操作:
Sub DeleteBlanks()
Dim TotalRows As Long
Dim i As Long
Dim j As Long
TotalRows = Rows(Rows.Count).End(xlUp).Row
For i = TotalRows To 2 Step -1
'Check if there is more than one blank cell
If Cells(i, 1).Value = "" And Cells(i - 1, 1).Value = "" Then
'Count the number of cells that are blank
Do While Cells(i - j, 1).Value = ""
If i - j <= 1 Then
Exit Do
End If
j = j + 1
Loop
'Delete group of blank of cells
If i - j <= 1 Then
Rows(i & ":" & i - j).Delete
Else
Rows(i & ":" & i - j + 1).Delete
End If
j = 0
End If
Next
End Sub