VBA or formula to mark or delete rows if not in range

thomassharp

Board Regular
Joined
Dec 10, 2014
Messages
84
Hello,
On Excel 2010.
Not sure if VBA is necessary here: I have two work sheets. Sheet1 with 10000 rows and the Sheet2 with 500 or so. All of Sheet2's data is in Sheet1. Sheet2 is just one column with values in column A; if those values are not in a specified column on Sheet1, i.e. any extra values, what would be the best way to delete the rows or just mark mark them in a helper column for deletion? I can't highlight duplicates then work backwards to get unique values as there are hundreds of duplicates in the sheet already. Everything I have read so far is for the reverse i.e. deleting rows if values are contained in a range.

Thank you



 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,461
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hello,
On Excel 2010.
Not sure if VBA is necessary here: I have two work sheets. Sheet1 with 10000 rows and the Sheet2 with 500 or so. All of Sheet2's data is in Sheet1. Sheet2 is just one column with values in column A; if those values are not in a specified column on Sheet1, i.e. any extra values, what would be the best way to delete the rows or just mark mark them in a helper column for deletion? I can't highlight duplicates then work backwards to get unique values as there are hundreds of duplicates in the sheet already. Everything I have read so far is for the reverse i.e. deleting rows if values are contained in a range.

Thank you



Assuming data in sheet1 are in A2:A10001 and data in Sheet2 are in A2:A501, in sheet2 cell B2 place this formula and copy down:
=IF(ISNA(MATCH(A2,Sheet1!$A$2:$A$10001,0)),0,1)

Now sort sheet2 columns A:B by col B, ascending and delete all the rows, if any, with a 0 in col B.
 

Forum statistics

Threads
1,136,201
Messages
5,674,384
Members
419,504
Latest member
tismail

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
Top