gpt4 book ai didi

excel - 如果它有 <30 行,则要删除整个列

转载 作者:行者123 更新时间:2023-12-04 22:28:37 26 4
gpt4 key购买 nike

我有多列和多行(> 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com