Delete a row on workbook 1 Sheet 1 if the same value is on workbook 1 Sheet 2

dmwilson38550m

Board Regular
Joined
Oct 29, 2010
Messages
67
Hi,

I wonder if anyone can help me - is there a macro I can use to delete an entire row on an Excel workbook (sheet 1 source data) if the same invoice number is noted on sheet 2 (reference sheet) of the same Excel workbook?

Thanks in advance.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
We need to know the two sheet names and in what column should we search for this invoice number

Are the sheets named "Sheet1" and "Sheet2"?
 
Upvote 0
Assuming your sheets are named "Sheet1" and "Sheet2"
And the invoice numbers are in column "A" on both sheets.
Try this:

Code:
Sub Invoice_Number()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim Lastrowa As Long
Lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
Lastrowa = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
Sheets("Sheet1").Activate
    For i = Lastrow To 1 Step -1
                    
            For b = 1 To Lastrowa
                If Cells(i, 1).Value = Sheets("Sheet2").Cells(b, 1).Value Then
                    Sheets("Sheet1").Rows(i).Delete
                End If
            Next
    Next
Application.ScreenUpdating = True
End Sub

OK
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,150
Members
448,552
Latest member
WORKINGWITHNOLEADER

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