Consulting

Results 1 to 2 of 2

Thread: search for data and delete rows containing it

  1. #1

    search for data and delete rows containing it

    I have an Excel workbook with 24 sheets of data. The first sheet contains data in Column A that is bad data that needs to be deleted from all the other worksheets.

    I will call the first worksheet with the bad data (1500 rows) "bad data"

    Would like to record a macro that looks at data in A1 cell of "bad data" worksheet, finds matching data in all other worksheets, deletes that entire row of data, then also deletes the bad data in the original worksheet "bad data".

    After delete row A in "bad data" worksheet, the bad data that WAS in A2 moves up to A1. would like to run the macro again using the new bad data that has been moved up to A1 as a result of previous deletions.

    Or run a macro that looks up all data from column A in the first worksheet (1500 rows) and deletes all rows with matching data in the other 24 sheets.

    The data is bad emails that i am deleting from my .csv email database file.



    I am willing to pay someone to write it for me.




  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Not sure if there are any more specifics, but this should get you started

    Public Sub DeleteBadData()
    Dim ws As Worksheet
    Dim lastrow As Long
    Dim findrow As Long
    Dim i As Long
    
        Application.ScreenUpdating = False
        
        With ActiveSheet
            
            lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
            For i = lastrow To 1 Step -1
            
                For Each ws In .Parent.Worksheets
                
                    If Not ws Is ActiveSheet Then
                    
                        findrow = 0
                        On Error Resume Next
                        findrow = Application.Match(.Cells(i, "A"), ws.Columns(1), 0)
                        On Error GoTo 0
                        If findrow > 0 Then ws.Rows(findrow).Delete
                    End If
                Next ws
            Next i
            
            .Columns(1).ClearContents
        End With
    
        Application.ScreenUpdating = True
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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