我正在尝试删除表S中列为空白的所有行(“ Table1
”)。
我收到错误“ 400”。
如果我将其替换& LastRow
为数字,例如“ S2:S1000”,则此宏有效。
Sub deleteBlankRows()
Dim LastRow As Long
LastRow = Range("B" & Rows.Count).End(xlUp).Row
With Range("S2:S" & LastRow)
.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
End Sub
发生错误是因为您要删除表中的整个行。您可以将表转换为范围,或在宏中使用Rows
而不是EntireRow
:
Sub deleteBlankRows()
Dim LastRow As Long
With ThisWorkbook.Worksheets("YourSheetName")
LastRow = .Range("B" & .Rows.Count).End(xlUp).Row
With .Range("S2:S" & LastRow)
.SpecialCells(xlCellTypeBlanks).Rows.Delete
End With
End With
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句