0 Or i = 100 Then Exit DoIf InStr(Range("A" & i), "x") > 0 ThenRows(i).De" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > VBA 如何将某一行中包含某些字段的单元格所在的列全部删除?

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

作者:乔山办公网日期:

返回目录:excel表格制作


Sub test()
Dim i As Integer
i = 1
Do While True
If InStr(Range("A1") & i, "y") > 0 Or i = 100 Then Exit Do
If InStr(Range("A" & i), "x") > 0 Then
Rows(i).Delete
Else
i = i + 1
End If
Loop
End Sub

x、y、100就是你的X、Y、N,请自己修改。

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

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


Sub 删除()
For i = 2 To [E65536].End(3).Row
If InStr(Range("E" & i), "数据") = 0 Or Not Range("G" & i) Then Range("E" & i).ClearContents
Next
Range("E:E").SpecialCells(4).EntireRow.Delete
End Sub

循环for 与判断if
如果数据量大装入数组判断;不过,你这只一行就没这必要了。

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网