删除另一个工作表中的整行

时间:2015-03-18 14:03:13

标签: excel vba excel-vba

Sheet1 A3中有一个号码(并非总是相同)

enter image description here

Sheet2中,我想删除整列,其中A列包含与Sheet1!A3相同的值(蓝色):

enter image description here

使用不同的数字:

enter image description here

和以前一样,我们删除了行:

enter image description here

......等等。

这是我的代码,但什么都没发生;没有错误,但没有删除任何行。

Dim rng As Range
    Dim WB As Workbook
    Dim i As Integer

      Application.ScreenUpdating = False
      Set WB = ActiveWorkbook
      Set rng = WB.Sheets("Données Enregistrées").Range("B:B").Find(What:=WB.Sheets("Modification").Range("A3"), _
             LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
      While Not rng Is Nothing
        rng.Rows("Modification").EntireRow.Delete
        Set rng = WB.Sheets("Données Enregistrées").Range("B:B").Find(What:=WB.Sheets("Modification").Range("A3"), _
                  LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
      Wend

      Application.ScreenUpdating = True

1 个答案:

答案 0 :(得分:-1)

好的,这个代码将为你完成这项工作我至少在删除部分,但你必须适应你的其余代码

你不清楚它发生了多少时间,所以只要你需要建立一个循环

Dim f       As String

f = Worksheets(1).Range("A3")
'Since i didn't got that clear, here above you must create 
'a code to declare "f" as whatever you want the code will than
'search that f value on the "A" column of Sheets(2) and delete 
'the first that contains that value, build a loop if it happens 
'more than once

Set c = Worksheets(2).Range("A:A").Find(f)

Range(c.address()).EntireRow.Delete