0

我要做的是让程序通过从一列单元格中找到某个值,并在我特别粘贴该值后查看它是否与一个单元格匹配,如果匹配则删除关联的单元格和它的一排单元格。发生的事情是程序的特殊粘贴部分正在工作,但相关的单元格没有被删除。为了澄清,我试图根据是否存在匹配从某一列中删除一整行

Dim j As Integer
Dim i As Integer
i = 2
Dim Aud_Tot As Integer
Aud_Tot = Application.InputBox("How big is your audit", , , , , , , 1)
Do While True
    If Cells(i, 1).Value <> "" And Not IsError(Cells(i, 2).Value) Then
        Range(Cells(i, 1), Cells(i, 22)).Copy
        Range(Cells(i, 1), Cells(i, 22)).PasteSpecial xlPasteValues
        For j = 2 To Aud_Tot
            If Cells(j, 24).Value = Cells(i, 2).Value Then
                Range(Cells(j, 24), (Cells(j, 42))).ClearContents
            End If
        Next j
        i = i + 1
    Else
        Exit Do
    End If
Loop
4

1 回答 1

1

似乎您想删除该行,但您只使用ClearContents. 要删除,您可以将该行更改为Range(Cells(j, 24), (Cells(j, 42))).Delete Shift:=xlShiftUp,也可以使用xlShiftToLeft.

您是要删除行还是只删除您拥有的范围?

于 2016-06-24T18:30:51.450 回答