如何删除空白列VBA
答
你可以试试这个:
Sub Main
Dim iCol As Long
With Worksheets("mySheetName").UsedRange '<--| change "mySheetName" to your actual sheet name
For iCol = .Columns.Count to 1 Step - 1
If WorksheetFunction.CountA(.Columns(iCol)) = 1 Then .Columns(iCol).EntireColumn.Delete
Next
End With
End Sub
答
Dim r As Range, rows As Long, i As Long
Set r = ActiveSheet.Range(Cells(1, 1), Cells(lastrow, lastcolumn))
rows = r.rows.Count
For i = rows To 1 Step (-1)
If WorksheetFunction.CountA(r.rows(i)) = 0 Then r.rows(i).Delete
Next
+0
-getting错误 - “运行时error'1004' :应用程序定义或对象定义的错误” –
收到错误消息“需要的对象“ –
什么行引发该错误? – user3598756
请参阅编辑错字代码(WorsheetFunction - > WorksheetFunction)。让我知道。 – user3598756