Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

VBA - need macro to delete rows if not on list

0

Hi, new to the forum but have been enjoying the YouTube channel.

The Ask is.

I have data one sheet1 with 30k+ rows and I have another sheet that has a list of values that the user puts in to keep on sheet1. Another requirement is that it may contain more columns.

For example.

Sheet 1 will generally have about 10 columns ranging from employee name, ID, etc.

Sheet2 won't have all these columns, but should allow flexibility to allow from 1-10 columns. The header for both sheets will be same. So let's say on sheet2 under Employee location column A, we have Canada then US. On sheet1, under the same header, if the cell doesn't match either Canada or US, that row gets deleted. 

Then on sheet 2 column B, it's Employee start date and then it has a list of dates. On sheet1, if the dates doesn't match, then that row gets deleted. 

Then if we have a column C, on the header row, if there is data, do the same. If column C header row doesn't contain any data, then macro should end.

I hope this makes sense.

Thanks in advanced.

Answer
Discuss

Discussion

Hi and welcome to the Forum

You've asked for a solution to a fairly big problem (akin to "Just fix this for me please"!) but we prefer it if you make an attempt to solve your own problem and ask a specific question when you get stuck.

Please do so and then EDIT your original question to attach your efforts in an Excel file containing some representatibve data (30 to 50 rows of anonymised test data say).
John_Ru (rep: 6142) Aug 24, '21 at 3:58 am
Add to Discussion



Answer the Question

You must create an account to use the forum. Create an Account or Login