我有多列和多行(> 200 行)。如果任何一列的数据 <30 行,我想删除整列。请帮忙
Sub Delete_EntireColumn()
Dim iCntr
For iCntr = 1 To 10 Step 1
Columns(1).EntireColumn.Delete
Next
End Sub
最佳答案
尝试
Sub Delete_EntireColumn()
Dim LCol as Long, LRow as Long, i as Long
With Workbooks(REF).Sheets(REF)
LCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
For i = LCol To 1 Step - 1
LRow = .Cells(.Rows.Count, i).End(xlUp).Row
If LRow < 30 Then
.Columns(i).EntireColumn.Delete
End If
Next i
End With
End Sub
编辑
如果行没有连续填充:
Sub Delete_EntireColumn()
Dim LCol as Long, LRow as Long, i as Long
With Workbooks(REF).Sheets(REF)
LCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
For i = LCol To 1 Step - 1
LRow = Application.WorksheetFunction.CountA(.Columns(i))
If LRow < 30 Then
.Columns(i).EntireColumn.Delete
End If
Next i
End With
End Sub
关于excel - 如果它有 <30 行,则要删除整个列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55377591/