• 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.

what is the best way to add columns using lookup while merging multiple sheets

Siraj

New Member
This is my first post in this forum. I am new to VBA programming. I have taken the VBA Classes offered at Chandoo.org and am trying to solve some real problems I have using VBA. I have lot of experience in programming other languages like Java and C++.


I have posted a similar question in Stackoverflow forum yesterday as I have used Stackoverflow for a long time. As per the posting etiquettes here, cross-posting is not good idea - please forgive me for violating this etiquette. I am not trying to post this question to get an answer quickly, but I really wanted to understand multiple perspectives from VBA experts and there seems to be a lot of them here in this forum. Only after posting in Stackoverflow, I realized that I could have posted here first. If I get solid responses here, then I know where to post my next question related to VBA.


Also, I am not doing a copy-and-paste from that question. I am taking the time to rewrite the question to make it more relevant for this forum as my starting point for this program was the lesson from Vijay Sharma, a teacher in the VBA classes.


Here is my scenario. Please know that I have changed the details to avoid posting confidential data. Also, I have tried to explain the problem using a common customer data set as that is something everyone can relate to easily. I have also tried to talk only about the essence of the problem I have. I can manage the rest of the details, which might add unnecessary complexity to this post.


I have a sheet called 'Details' which has sales details of each customer by product - product name, unit price, quantity, total cost, etc. CustomerID is stored in another sheet called 'Summary'. A number of these files are stored in a directory organised by subfoders based on the person responsible for the customer. I have to do merge data from all these sheets into one target sheet, with customer ID and the sales data by product merged together.


In my current program, I am walking through all the folders starting with the top-level folder and opening each workbook and reading data from the 'Details' sheet and then I paste the data into the destination workbook. After I finish pasting, I read the customerID and fill it in the destination range.


Now, I have to add some columns related to the customer (like country, currency, region, etc.) by using a customer master workbook which stores customer data by customer ID. For products, I have to use a product master workbook and use the name to lookup and get product category and subcategory.


What I need help is to figure out the best approach to solve this problem. I have already written the code for merging the data from multiple workbooks and now I have to add the lookup columns. Here is the pseudo-code of the approach I am about to take:

[pre]
Code:
For each workbook in the source Folder
    Open source workbook
    Copy the range from details sheet
    Copy the customerID from summary sheet
    Open target workbook
    Paste range from source.details in the target worksheet
    Fill the range in the target worksheet with the first column as customerID
    Open workbook with customer master data
    Copy data based on customerID
    Paste in the target worksheet using fill range
Open workbook with product master data
Copy data based on product name
Paste in the target worksheet using fill range
Process next source workbook
[/pre]

Now, I would like to know what is the best way to solve this problem? This program will process around 500 workbooks and the target workbook is expected to have around 100K rows. So, I need a design which performs well.


I am interested in copying and pasting the values only. I need to do some formatting of the number columns, but I can do that in the VBA code after processing all source files rather than copying and pasting with formatting on.


And I am not sure whether it is good etiquette to include the link to the post in Stackoverflow. Here is the link - please correct me if this is not a good practice here.

http://stackoverflow.com/questions/12680552/how-to-add-some-lookup-data-while-merging-multiple-workbooks-into-one
 
Hi, Siraj!


First of all welcome to Chandoo's website Excel forums. Thank you for your joining us and glad to have you here.


As a starting point I'd recommend you to read the three first green sticky topics at this forums main page. There you'll find general guidelines about how this site and community operates (introducing yourself, posting files, netiquette rules, and so on).


Among them you're prompted to perform searches within this site before posting, because maybe your question had been answered yet.


Feel free to play with different keywords so as to be led thru a wide variety of articles and posts, and if you don't find anything that solves your problem or guides you towards a solution, you'll always be welcome back here. Tell us what you've done, consider uploading a sample file as recommended, and somebody surely will read your post and help you.


And about your question...


If you haven't performed yet the search herein, try going to the topmost right zone of this page (Custom Search), type the keywords used in Tags field when creating the topic or other proper words and press Search button. You'd retrieve many links from this website, like the following one(s), maybe you find useful information and even the solution. If not please advise so as people who read it could get back to you as soon as possible.


http://chandoo.org/forums/topic/excel-files-documenting-inspector

http://chandoo.org/forums/topic/folders-files-matching


Even if in these topics is not solved exactly what you're asking for, I hope you'd find them interesting as a kickoff. If so and you couldn't manage to handle the requires updates and fixes please advise.


Regards!
 
Back
Top