VBA 如何将某一行中包含某些字段的单元格所在的列全部删除?

例如行4中所有包含"*max*"或"*min*"字段的所在列全部删除,如图中的F, G列

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

写好时发现已经有知友回答了, 而且他的回答很赞. 但是既然写了就贴出来吧, 结果都一样, 细节处理略有不同.

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-09-20
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

请测试

本回答被提问者和网友采纳
相似回答