PDA

View Full Version : search for data and delete rows containing it



RickStewart
02-24-2014, 01:07 AM
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.

Bob Phillips
02-24-2014, 01:48 AM
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