VBA Loop to bring over data from multiple sheets using header and column data

MHamid

Active Member
Joined
Jan 31, 2013
Messages
472
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I have been trying to figure out the best way to accomplish this task.
I need to bring over data from multiple sheets (4 sheets to be exact), into the main sheet using headers as a point of reference for the data that I need brought over but it also has to match with the account number. I can't upload a mini sheet or use XL2BB add-in since it's company data. I could try to send dummy data as an example later today, but want to know if it's possible and how would you approach this scenario.

There are 5 Sheets total:
  1. Main
  2. Source1
  3. Source2
  4. Source3
  5. Source4
  6. Source5
When bringing over the data from the Source sheets. Source1 takes priority, then Source2, then Source3, then Source4, and then Source5. VBA should look for account number from Main sheet in the Source1 sheet first and if account number is not in Source1, then it would look in Source2, and so forth bringing over data based on headers. If header from main sheet does not exists in Source1 or Source2 or so forth, then leave blank

Main Sheet:
Account NumberAudit NameRegionClusterCountryBusiness L1 (Home)Business L2 (Home)
A123456
A456789
A789123


Source1:
Account NumberAccount NameRegionClusterCountryBusiness L1 (Home)Business L2 (Home)
A123456Acct Name1EMEAEMEA EM;Turkey, Russia, Ukraine, and Kazakhstan (TRUK)Turkey(TR)Business 1Business2
A741852Acct name 2North AmericaNorth AmericaUS(US)Business 3Business 4
A852963acct name 3North AmericaNorth AmericaUS(US)Business 5Business

Source2:
Audit_IDAccount NameCountryRegion
A456789name1Japan(JP)Japan
A852741name2US(US)NAM
A753412Singapore Interbank Offered Rate (SIBOR)Singapore(SG)Asia Pacific


Source3:
Audit_IDAudit NameCountryRegionCluster
A789123name6Country listashfgajkfgCluster list
A777777name7US(US)NAMNorth America
A444444name8ahgsfjaghafgajgfakjshfkajh

Source4:
Account NumberAccount_Name
A888888adfgasdfaljhklasfjh
A555555ajfhgajkgfkasfh

Source5:
Audit Shell IDAudit NameCountry (Home)Region (Home)Cluster
A333333name1LATAM Hub(X7)LATAM
A666666name2US(US)NAMNorth America
A858585name3Vietnam(VN)Asia PacificAsean

Please let me know if I need to clarify anything.


Thank you,
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
anyone has any advice or need any further information?
 
Upvote 0
5. Where and how often you get the data to/for sheet1-5
5.1 Can't influence the structure of the data available? (column headings and order?)
5.2 How many rows can there be on each sheet?


If you can't influence the structure ...

1. Do you want to fill the Main sheet according to the Account number already in it?

2. Information to be filled can be found in Source 1,2,3,4,5 sheets?

3. Search in order of sheet number?

4.Is the data in a table object or just a sheet?

6. Can the same Account Number be found on more than one sheet?

7. Can the same Account Number get data from more than one sheet to same column of the Main Sheet?

8. Can different sheets give different data for same cell in Main-sheet? -> Sheet3 data is overwritten by data received from Sheet1?
 
Upvote 0
5. Where and how often you get the data to/for sheet1-5
5.1 Can't influence the structure of the data available? (column headings and order?)
5.2 How many rows can there be on each sheet?


If you can't influence the structure ...

1. Do you want to fill the Main sheet according to the Account number already in it?

2. Information to be filled can be found in Source 1,2,3,4,5 sheets?

3. Search in order of sheet number?

4.Is the data in a table object or just a sheet?

6. Can the same Account Number be found on more than one sheet?

7. Can the same Account Number get data from more than one sheet to same column of the Main Sheet?

8. Can different sheets give different data for same cell in Main-sheet? -> Sheet3 data is overwritten by data received from Sheet1?
Hello,

Source1 - we can call this 'MonthlyRefresh'
Source2 - 'WeeklyRefresh1'
Source3 - 'WeeklyRefresh2'
Source4 - 'ManuallyAddedItems'
Source5 -'PreliminaryData'

5. An outside source provides data for sheets 1-3. Sheet1 is received monthly while sheets 2 and 3 are received weekly. Sheet4 is for data that we receive sporadically and have to be manually added into sheet4 (this will be weekly, but only if we receive any data, if not it's fine). Sheet 5 is preliminary data from the beginning of the year (this sheet data never changes throughout the year).
5.1 Not sure what you mean by influence the structure, but I think the columns header names can be used to bring over data since they will most likely be the same (or I can make the names match).
5.2 Row count varies, but it is definitely over 850 rows of data ... sometimes it can go over 900 or 1000 rows of data. But the account number column can be used from the main sheet to determine the row count.


if can't influence the structure ...
1. Yes, the account number from the main sheet should be used to find the corresponding data for that account number
2. Yes, the information is found in sheets 1-5
3. Yes, the Source1 will always be first and if account number is not in Source1, then search for account number in Source2. If account number is not found in Source2, then search in Source3. If not found, then search in Source4. If not found then search in Source5.
4. No table, just a sheet
6. Yes, the same number can be found on more than one sheet, but please use the order I mentioned in #3
7. Even if account number exists in other sheets, the data brought over should be entered based on the priority level in #3. So if an account number is found in both Source1 and Source2, I just want the data from Source1 brought over.
8. Different sheet may have different data, but Source1 data will always be the most up-to-date data, which is why this data should be brought over first and never be overwritten.


Please let me know if you have further questions and what your thoughts are to make this happen.


Thank you,
 
Upvote 0
Hello,

Anyone has any advise with what I have provided so far? Does anyone need more information to assist?

Thank you,
 
Upvote 0

Forum statistics

Threads
1,214,857
Messages
6,121,948
Members
449,056
Latest member
FreeCricketId

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
Back
Top