Delete entire row when a value exist in a second sheet

后端 未结 2 1146
孤独总比滥情好
孤独总比滥情好 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.

    0 讨论(0)
  • 2021-01-27 07:25

    Sub Test()

    Dim ws As Worksheet

    For x = 1 To Rows.Count

    If ThisWorkbook.Sheets("Sheet2").Cells(x, 1).Value = ThisWorkbook.Sheets("Sheet1").Cells(3, 1).Value Then ThisWorkbook.Sheets("Sheet2").Cells(x, 1).EntireRow.Delete

    Next x

    End Sub

    0 讨论(0)
提交回复
热议问题