• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA vlookup based on criteria

ahmed.sange

New Member
Hi ,

I'm looking for some assistance in developing a macro for the below:
  1. I have two workbooks (book1 & book2) with a primary key (i.e. a common column of data - i.e. item code). Both the workbooks are dynamic (i.e. there may be new columns and rows added onto both the workbooks). Book 1 contains the data/table from where I want to vlookup data onto book 2 based on conditions. Please view the attached 2 workbooks.
  2. I want the macro to find the 'month' in book1 and then vlookup that data onto the same month column of book2 based on the item code. (e.g. To vlookup august data on book2, I want the macro to find august on book1 and then vlookup data based on the item code)
  3. This is because there will be new columns (i.e. new month columns) added to book1 on a monthly basis.
Please help as all my attempts have failed.
 

Attachments

  • Book1 - Sample.xlsx
    11.1 KB · Views: 2
  • Book2 - Sample.xlsx
    12.7 KB · Views: 2
Hi,

If you can arrange the headings to be consistent in both the books, then you can acheive this without any macros.

for example, in book 1, i changed the "August " to "August", and in book2 i changed "August (2014)" to "August". Similarly for other months headings as well.

And, then using the below formula you get the desired results:

=SUMPRODUCT(('[Book2_-_Sample(1).xlsx]Sheet1'!$B$3:$B$19=$B5)*('[Book2_-_Sample(1).xlsx]Sheet1'!$I$1:$AB$1=G$2)*('[Book2_-_Sample(1).xlsx]Sheet1'!$I$3:$AB$19))

Regards,
Prasad DN.
 
Hi Prasad,

Thanks for the input.
However, the headers or columns cannot be consistent. Because, Book1 would have new columns added every month.
Thus, I need to develop a macro that identifies the month on Book1 and accordingly updates information on Book2 where the lookup value would be the item code.
 
Back
Top