我对VBA很新。行和列都有标题,如果它们分别没有任何数据,我需要隐藏它们。
答案 0 :(得分:0)
应该做的伎俩
Sub main()
Sheets("Sheet1").Activate
Dim i As Integer
Dim firstColumn, lastColumn, firstRow, lastRow As Integer
firstColumn = 1
lastColumn = 10
firstRow = 1
lastRow = 10
' Check if column has any data beside its header
For i = firstColumn To lastColumn
Columns(i).Hidden = (WorksheetFunction.CountA(Columns(i)) < 2)
Next i
' Check if row has any data beside its header
For i = firstRow To lastRow
Rows(i).Hidden = (WorksheetFunction.CountA(Rows(i)) < 2)
Next i
End Sub