Delete row if specific cell value matches value found in another worksheet

zicitroj

New Member
Joined
Mar 22, 2011
Messages
6
Hi all,

Can anyone please help me this problem?

I need a formula or VBA macro to do the following:

I have 2 worksheets, namely sheet 1 and sheet 2.
Sheet 1 contains data in columns A to H.
Sheet 2 contains data only in column A.
I want Excel to check the data found in column A of Sheet 2 with those in Column A of Sheet 1. Hence, when an exact match is found in Column A of Sheet 1, Excel will delete that entire row.

Thanks a lot for your help!

regards,
Ali
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi. Assuming that you want to delete the rows from Sheet1 try

Code:
Sub CheckA()
Dim LR As Long, i As Long
With Sheets("Sheet1")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = LR To 1 Step -1
        If IsNumeric(Application.Match(.Range("A" & i).Value, Sheets("Sheet2").Columns("A"), 0)) Then .Rows(i).Delete
    Next i
End With
End Sub
 
Upvote 0
Hi. Assuming that you want to delete the rows from Sheet1 try

Code:
Sub CheckA()
Dim LR As Long, i As Long
With Sheets("Sheet1")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = LR To 1 Step -1
        If IsNumeric(Application.Match(.Range("A" & i).Value, Sheets("Sheet2").Columns("A"), 0)) Then .Rows(i).Delete
    Next i
End With
End Sub

This is great!

it works however i need help reversing the action. What i need to have happen is if the result is not found on sheet 2, then i want the entire row deleted, is that possible?

i have search various VB arguments and cant find how to rever match to something else.

Thanks!
 
Upvote 0
Try

Rich (BB code):
Sub CheckA()
Dim LR As Long, i As Long
With Sheets("Sheet1")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = LR To 1 Step -1
        If IsError(Application.Match(.Range("A" & i).Value, Sheets("Sheet2").Columns("A"), 0)) Then .Rows(i).Delete
    Next i
End With
End Sub
 
Upvote 0
:)thanks a million for the help this worked perfectly!

Great site and community here!

This is great!

it works however i need help reversing the action. What i need to have happen is if the result is not found on sheet 2, then i want the entire row deleted, is that possible?

i have search various VB arguments and cant find how to rever match to something else.

Thanks!
 
Upvote 0
Hi,

I need a macro that can do exactly this except that it can do it throughout the whole workbook.

To give you more details about my situation:
I have a list with 35 unique serial numbers in Sheet 1.
These serial numbers are always found in column C, but are spread out throughout the entire workbook (between 30 and 100 different sheets)
I want the macro to find instances of the serial numbers in Sheet 1 and automatically delete the rows containing them in the rest of the workbook.

Ideally, when a match is found and a row is, the serial numbers in Sheet 1 will be highlighted.

Is this something you guys can help me out with?


Thanks!!
 
Upvote 0
Hi

You have posted to an old thread. Many members including me are now "retired" from the board. Please start your own, new, thread. :biggrin:

Hi,

I need a macro that can do exactly this except that it can do it throughout the whole workbook.

To give you more details about my situation:
I have a list with 35 unique serial numbers in Sheet 1.
These serial numbers are always found in column C, but are spread out throughout the entire workbook (between 30 and 100 different sheets)
I want the macro to find instances of the serial numbers in Sheet 1 and automatically delete the rows containing them in the rest of the workbook.

Ideally, when a match is found and a row is, the serial numbers in Sheet 1 will be highlighted.

Is this something you guys can help me out with?


Thanks!!
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top