VBA 如何将某一行中包含某些字段的单元格所在的列全部删除?
发布网友
发布时间:2022-10-03 12:48
我来回答
共2个回答
热心网友
时间:2023-10-10 10:26
Sub DeleteColumns()
Dim i As Long, maxCol As Long
Dim str As String
maxCol = Cells(4, Columns.Count).End(xlToLeft).Column
For i = maxCol To 1 Step -1
str = Cells(4, i)
If (str Like "*min*") Or (str Like "*max*") Then
Cells(4, i).EntireColumn.Delete
End If
Next i
End Sub
写好时发现已经有知友回答了, 而且他的回答很赞. 但是既然写了就贴出来吧, 结果都一样, 细节处理略有不同.
热心网友
时间:2023-10-10 10:26
Sub test()
num = 256
For i = 1 To 256
If Cells(4, num).Value Like "*max*" Or Cells(4, num).Value Like "*min*" Then
Columns(num).Delete
End If
num = num - 1
Next
End Sub
请测试