EXCEL VBA 怎样删除某一列符合某个条件的行?

2024-12-04 07:47:08
推荐回答(1个)
回答1:

Sub 删除重复数据() '以col列为条件删除的重复行数据 '本例是删除标题为sheet1的EXCEL表中以A列(从A2单元格开始)为条件的重复韩国数据 Application.ScreenUpdating = False '可根据实际情况修改下面三行的结尾值 'MsgBox "请确认子表名称是否是 当前告警实时监控?"Dim sheetsCaption As String: sheetsCaption = "当前告警实时监控" 'MsgBox "请确认或修改到底 删除哪一列的重复数据?" Dim Col As String: Col = "C" Dim Col1 As String: Col1 = "E" 'MsgBox "请确认或修改该列的第几行开始核查所有数据是否有重复数据?" Dim StartRow As Integer: StartRow = 3 '以下不需要修改 Dim EndRow As Integer: EndRow = Sheets(sheetsCaption).Range(Col & "65536").End(xlUp).Row MsgBox EndRow Dim i As Integer: i = StartRow With Sheets(sheetsCaption)DoIf Left(.Range(Col1 & i), 4) < "SDR:" Then .Range(Col1 & i).Select Selection.EntireRow.Delete EndRow = Sheets(sheetsCaption).Range(Col1 & "65536").End(xlUp).Rowi = i - 1End Ifi = i + 1'MsgBox i 'MsgBox EndRow