逐行,如果单元格H =单元格I,则删除整行

时间:2019-01-24 08:38:38

标签: excel vba

如果单元格H1 =单元格I1,则删除整行。然后下一行,单元格H2 <>单元格I2,保持不变。然后下一行。

如果该行的两个单元格都相同,我想删除整行。我进行了搜索,这与我想要实现和修改的代码最接近。

Sub CellAequalCellB ()
    Dim ws As Worksheet
    Dim rng As Range
    Dim lastRow As Long

    Set ws = ThisWorkbook.Sheets("Sheet1")

    lastRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row

    Set rng = ws.Range("H1:I" & lastRow)

    ' filter and delete all but header row
    With rng
        .AutoFilter field:=1, Criteria1:=" .AutoFilter field:=2 "

SpecialCells(xlCellTypeVisible).EntireRow.Delete
    End With

    ' turn off the filters
    ws.AutoFilterMode = False
End Sub

但是,当我运行时,wholerow.delete会出错。

1 个答案:

答案 0 :(得分:1)

您的自动过滤器代码有很多错误,因此我将方法更改为简单的向后循环。

@Fi&@Im&@In.js:274 dojo/parser::parse() error TypeError: 
 CKEDITOR.scriptLoader.queue is not a function
 at Object.$DDMp_ [as _postCreate] (@Fi&@Im&@In.js:443)
 at Object.$DDMl_ [as postCreate] (@Fi&@Im&@In.js:443)
 at Object.$DDDD_ [as create] (@Fi&@Im&@In.js:163)
 at Object.$DDDC_ [as postscript] (@Fi&@Im&@In.js:163)
 at new <anonymous> (dojo.js:15)
 at Object.$DDSv_ [as construct] (@Fi&@Im&@In.js:274)
 at Object.<anonymous> (@Fi&@Im&@In.js:274)
 at Object.$DDSY_ [as map] (dojo.js:15)
 at Object.$DDSu_ [as _instantiate] (@Fi&@Im&@In.js:274)
 at @Fi&@Im&@In.js:274
 (anonymous) @ @Fi&@Im&@In.js:274
dojo.js:15 TypeError: this.editor.getData is not a function
 at Object.$DDMu_ [as getValue] (@Fi&@Im&@In.js:443)
 at x_sl.view__id1__id166__id167__id214_body1_rteSubmit [as listener] 
 at x_sl.xsl_r [as run] (@Fi&@Im&@In.js:289)
 at _3.x_pls [as _processListeners] (@Fi&@Im&@In.js:289)
 at _3.x_dfe [as _doFireEvent] (@Fi&@Im&@In.js:289)
 at _3.x_fpar [as firePartial] (@Fi&@Im&@In.js:289)
 at xaep_fpre (@Fi&@Im&@In.js:289)
 at _3.x_aep [as _attachEventOrPartial] (@Fi&@Im&@In.js:289)
 at _3.x_apar [as attachPartial] (@Fi&@Im&@In.js:289)
 at documents.xsp?