Excel VBA正在查找每个其他单元格,而不是方法中的每个单元格

Excel VBA正在查找每个其他单元格,而不是方法中的每个单元格,excel,vba,Excel,Vba,Excel VBA正在使用检查空单元格的方法查找其他每个单元格。下次运行同一个宏时,它将查找上次运行时跳过的单元格,同时再次跳过空单元格的下一个实例。如果我在宏中循环几次,最终会根据宏的用途删除没有数据的每一行。每次删除一行时,行确实会向上移动,我将尝试联合并删除@BigBen所述的范围 当找到空的单元格时,它会检查列a、B和D以查看是否应用了公式,如果该行中存在公式,则会删除整行 Dim cel, dataCells As Range Dim rngBlank, dc As Range Dim

Excel VBA正在使用检查空单元格的方法查找其他每个单元格。下次运行同一个宏时,它将查找上次运行时跳过的单元格,同时再次跳过空单元格的下一个实例。如果我在宏中循环几次,最终会根据宏的用途删除没有数据的每一行。每次删除一行时,行确实会向上移动,我将尝试联合并删除@BigBen所述的范围

当找到空的单元格时,它会检查列a、B和D以查看是否应用了公式,如果该行中存在公式,则会删除整行

Dim cel, dataCells As Range
Dim rngBlank, dc As Range
Dim lastRow, cForm, c, blnkRange As String
Dim cycleTimes As Integer

On Error Resume Next

Set dataCells = Range("F2:W2").Cells    'This is header of the table of data
cycleTimes = dataCells.Count            'Number of times to cycle through macro

For Count = 1 To cycleTimes             'I don't want to cycle through macro
    lastRow = Range("N" & Rows.Count).End(xlUp).Row   'To find end of column
    For Each dc In dataCells
        c = Split(Cells(1, dc.Column).Address, "$")(1)    'Column Letter
        blnkRange = c & "3:" & c & lastRow                'Range to look over for empty cells
        Set rngBlank = Range(blnkRange).SpecialCells(xlCellTypeBlanks).Cells
        For Each cel In rngBlank                          '**Skipping Every other Row**
            If Not TypeName(cel) = "Empty" Then
                cForm = "A" & cel.Row & ",B" & cel.Row & ",D" & cel.Row  'Formula check
                If Range(cForm).HasFormula Then
                    cel.EntireRow.Delete
                End If
            End If
        Next
    Next
Next

我能够使用Intersect查找与我正在搜索的条件匹配的行,并删除整个行,即使选择在单独的行中

Set dataCells = Range("F2:W2").Cells

lastRow = Range("N" & Rows.Count).End(xlUp).Row  'To find last row to generate range to look through
For Each dc In dataCells                         'Have to perform delete row for every column
    c = Split(Cells(1, dc.Column).Address, "$")(1) 
    blnkRange = c & "3:" & c & lastRow
    Set rngBlank = Range(blnkRange).SpecialCells(xlCellTypeBlanks).EntireRow
    strFormula = "A2:A" & lastRow & ",B2:B" & lastRow & ",C2:C" & lastRow
    Set rngFormula = Range(strFormula).SpecialCells(xlCellTypeFormulas)
    Intersect(rngFormula, rngBlank).EntireRow.Delete (xlShiftUp)  '**THIS helped in deleting Rows**
Next

您应该为要删除的范围创建一个
并集
,然后在末尾一步删除。删除一行时,是否将其余行上移(或降低其索引)?如果是这样的话,你会想把所有的都标记为删除,并像BigBen所说的那样一次完成。投票结束作为
通用软件问题
。提出的问题“以下代码中的哪些内容可以更改以避免此行为发生”会让我相信您正在使用另一个人的代码,但不了解发生了什么,因此请其他人理解代码并进行更新。请更新您的帖子,使其更加具体,并提供您尝试过的thusfar。@Cyril我在旁边发表了评论,其意图如上所述,并在前两条评论中得到了回答。您完全可以删除不连续的行。例如,请参见,它使用
联合