Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

extracting data many worksheets

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Extracting Data from many worksheets

Extracting Data from many worksheets

ResolvedVersion 2003

Rory has attended:
Excel VBA Intro Intermediate course

Extracting Data from many worksheets

How do you code VBA so that within a particular folder (say C:mydocuments/Excel), open every document in turn and perform the same task on each document. For example if data need to be extracted from many returned forms and all such forms are saved in the same location.

RE: Extracting Data from many worksheets

Thank you for your question.

The command you need is Dir which returns filenames. The first time you use it you specify the location and mask and then you just use dir to find the next match. When dir finds no more files it returns an empty string.

Example

Sub ReportFiles()

Dim FoundFile As String
'Find first file
FoundFile = Dir("c:\reports\*.xls")
Do While FoundFile > ""
Workbooks.Open FileName:="c:\reports\" & FoundFile
' Process each file
'
' Get name of next file
FileName = Dir
Loop

End Sub




Please let me know how you get on.


Laura GB

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Reconciling a list to correspond with another

May have a list that needs to make but on another sheet one list seems to be out, eg. product list one sheet contains all product and inventory data, while the other contains pricing data. Both need to match with all products but there is more products in one list than the other. To find the disparaging product compare data in the two columns that need to match Make sure that order the same way.
Create another column in the sheet that has the most items and type in the first cell


=Exact(text1,text2) text1 being the cell that you want compared with text2 cell reference. Drag to filldown and your first false will give you for first cells that does not match. Correct insert the row with data in other sheet and continue the process until all the data returns true. Delete the column inserted.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.