Consulting

Results 1 to 4 of 4

Thread: match delete vba

  1. #1
    VBAX Regular
    Joined
    May 2016
    Posts
    69
    Location

    Talking match delete vba

    If sheet 2 shows a specific number in column A, I want it to delete the row that in Sheet1 that has a matching number in column 3.

    Please, advise the quickest way to look through multiple numbers in sheet2 and delete all matches in Sheet1.
    Last edited by SamT; 05-25-2016 at 08:09 AM. Reason: Deleted Font Name Formatting

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Loop thru the used cells in column A

    Use iterative "Find" on Column C, Be sure to Set "From" = C1 and "Direction" to xlPrevious
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Some data type assumptions made
    Sub Macro1()
    
    
        Dim Crit()
        Dim Data As Range, cel As Range
        Dim r As Range
        Dim i As Long
        
        Set r = Sheets(2).Columns("A:A").SpecialCells(xlCellTypeConstants)
        ReDim Crit(r.Cells.Count - 1)
        For Each cel In r
            Crit(i) = Str(cel)
            i = i + 1
        Next
        Set Data = Sheets(1).Columns("C:C").SpecialCells(xlCellTypeConstants)
        Data.AutoFilter Field:=1, Criteria1:=Crit, Operator:=xlFilterValues
        Data.SpecialCells(xlCellTypeVisible).EntireRow.Delete
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Regular
    Joined
    May 2016
    Posts
    69
    Location
    Many Thanks!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •