Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find worksheet and import data?

Status
Not open for further replies.

MrMask

Electrical
Sep 23, 2006
15
Hi folks

I need help on loading data from many different workbooks into a different workbook/worksheet so I can analyse the data. All Excel files have the same path, but some workbooks have the specific worksheet others not. The specific worksheets have the same name and the cell range is the same.

E.g.: look for worksheet "W1" on different workbooks; if available, copy the cell range and past on column A, B, C.... (for each data set) on worksheet "summary" of workbook "Data". Row 1 needs to have the workbook name for identification.

Likely this solution is available in this forum, so send me the links so I can start.

Thx
 
Replies continue below

Recommended for you

If the solution is ready made then use of the Search facility may find it. I didn't see a ready made answer so I've knocked up a quick solution for opening the workbooks. Getting the data from each should then be fairly trivial by simply recording a macro, and substituting to reference in your code.
Code:
Private Sub CommandButton1_Click()
Dim curbook As String
Dim myERR As Integer
Dim strFile As String
Dim Counter As Integer
On Error GoTo myERR
curbook = Workbooks(1).Name
Counter = 0
strFile = Dir("F:\My Documents\Worksheets\*.xls")
Do While Len(strFile) > 0
Counter = Counter + 1
If strFile <> curbook Then
    Workbooks.Open Filename:=strFile
    Sheets("w1").Select
End If
strFile = Dir
Loop
Exit Sub
myERR:
If Err.Number = 9 Then
Workbooks(Counter).Close
Resume Next
End If
End Sub

You will need to change strFile = Dir("F:\My Documents\Worksheets\*.xls") to point to your own directory of course

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting

Steam Engine enthusiasts:
 
thanks for the input. I'll try it later and let you know. rgds
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor