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

Excel Macros

0

I have 2 sets of Excel Database which can be mapped using a unique ID. In database 2 I have values 1,2,3,4 in a column which are not there in database 1. I need to identify these values database 2, match them to a unique id in database 1 and delete rows which have values 1 and 2 based on database 2. 

How do I write a macro for the same? 

Answer
Discuss

Answers

0

I would start by creating a function that examines entries in DB1 to find one which contains values 1 and 2. If such an entry is found the function should return True, False if no such match exists. Values 1 and 2 are variable. They are passed to the function as arguments by the calling procedure.

Next, I would create the calling procedure. It loops through all entries in DB2 and picks Values1 and 2 from each row, passing them to the function. If the function, working with the received values, returns True (meaning that a match was found) that particular line is deleted from DB2. Else, no action is taken.

Note that it is important to construct this loop to start from the bottom of DB2 and work backwards to the top. This is because row numbers in a worksheet change when a row is deleted. Working bottom to top ensures that such changes affect only the part of the worksheet that has already been examined.

Discuss


Answer the Question

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