Delete entire row when a value exist in a second sheet

后端 未结 2 1147
孤独总比滥情好
孤独总比滥情好 2021-01-27 06:58

I have 2 sheets: sheet1 and sheet2. I have a value in cell A3 (sheet1) which is not constant. And many files in sheets2.

What I would like to do, is when the value in ce

2条回答
  •  深忆病人
    2021-01-27 07:24

    My guess is that you're not finding anything with the .Find(). Since you're not checking it for is Nothing you don't know. Also, .Find() retains all the search parameters set from the last time you did a search - either via code or by hand in your spreadsheet. While only the What parameter is required, it's always worth setting the most critical parameters (noted below) for it, you may want to set them all to ensure you know exactly how you're searching.

    Dim f As String
    
    If Worksheets("Sheet1").Range("A3").Text = Worksheets("Sheet2").Range("A:A").Text Then
      f = Worksheets("Sheet1").Range("A3")
      Set c = Worksheets("Sheet2").Range("A:A").Find(What:=f, Match:=[Part|Whole], _
              LookIn:=[Formula|value])
      if not c is Nothing then
        Worksheets("Sheet2").Range(c.Address()).EntireRow.Delete
      else
        MsgBox("Nothing found")
      End If
    End If
    

    Go look at the MS docs to see what all the parameters and their enumerations are.

提交回复
热议问题