Macro to pull in data from the file i'm in

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I have a Document and I need to pull in data from other documents?

So I want a macro that when I run it does the following,
Opens All xlsx file in the folder my document is saved in that start with the word "Date_"

and pull them into my document into one sheet.

but there are a few conditions

First I'd like to safe guard against bad data but checking the headers are the same
and secondly I like to pull in the data from every sheet in each document not just one.

So if I was writing this in English it would go something like this:

For each xlsx document in current folder,
If documents name is "Date_*something*" then,
for each sheet in document
check if headers in range A1:P1 Match this document sheet "master" range "A1:P1"
if they don't match,
In Sheet "Unmatched" starting in A2 tell me the Document Name, and Sheet name. and continue
If they do match then copy values of each sheet from A2 to P & Last row
paste to this document sheet "master" Column "A" lastrow + 1

Continue until all sheets and documents are done.
If on finish sheet "Unmatched" has any data then msgbox "All Done, But some of the Sheets had bad data so I've not pulled them in just listed them here!"
and select sheet "Unmatched"

if not then msgbox "All done, No problems"

save doc.

…....

so if anyone can help me with this that would be great thank you very much

Thanks

Tony
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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