你好。所以,我有一个包含 3 个标题的 Excel 表格:全名|邮件 |姓名(A1、B1、C1)。
例如,我的单元格 A2 没有值,在这种情况下我只想删除 A2、B2、C2 单元格。如果 A3 单元格有价值,我想保留全部(A3、B3、C3)。如果 A4 单元格没有值,我想删除单元格 A4、B4、C4 并保留它,直到 A 列中具有值的最后一行。我已经尝试用谷歌搜索它,我发现了几个选项,但它没有成功(大多数选项删除整行)。代码可能并不难,但我现在无法解决这个难题......
下面的解决方案应该适合您所描述的情况。
Sub DeleteRows()
Dim ws As Worksheet
Dim lastRow As Long, x As Long
Set ws = ActiveSheet
'get the last row with data in column A
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
'loop through all rows bottom to top
For x = lastRow To 2 Step -1
'if cell A in a row is blank
If ws.Cells(x, 1) = "" Then
'delete those rows of the table
ws.Range(ws.Cells(x, 1), ws.Cells(x, 3)).Delete Shift:=xlUp
End If
Next x
End Sub