如果行数少于30,则要删除整列

时间:2019-03-27 12:48:01

标签: excel vba

我有多列和多行(> 200行)。如果某列的数据少于30行,我想删除整列。请帮助

Sub Delete_EntireColumn()
Dim iCntr
    For iCntr = 1 To 10 Step 1
        Columns(1).EntireColumn.Delete
    Next
End Sub

1 个答案:

答案 0 :(得分:2)

尝试

fields

编辑

如果行没有连续填充:

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