tonywatsonhelp
Well-known Member
- Joined
- Feb 24, 2014
- Messages
- 3,210
- Office Version
- 365
- 2019
- 2016
- Platform
- 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
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