getting data from a collection of workbooks into 1 single master file

Schzuki

New Member
Joined
Jun 6, 2013
Messages
34
Hi,

I'm trying to collect specific data from a collection of different (.xls) files into 1 master file using the following code (which runs in the master file):

Code:
Sub FolderPick()
[B][COLOR=#800080]Set fso = CreateObject("Scripting.FileSystemObject")

    With Application.FileDialog(msoFileDialogFolderPicker)
        .InitialFileName = ThisWorkbook.Path  ' Give the path
        .Title = "Please select a folder to list Files from"
        If .Show = True Then
        Else
            Exit Sub
        End If
    End With

[U] FldPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)[/U]
 Set folder = fso.GetFolder(FldPath)

For Each file In folder.Files
    c = c + 1
Name = file.Name[/COLOR][/B]

Workbooks.Open Filename:=[B][COLOR=#ff0000]"Path\****************" & Name & "*************" & ".xls"""[/COLOR][/B]
Mixture = Workbooks(Name).Worksheets("general").Cells("a4").Value
current = ThisWorkbook.Worksheets("stuff")

'lookup value in list, set row nr
Row = Application.WorksheetFunction.Match(Mixture, Range("B3:B60"), 0)

'goto report file, tab results

'find scenario and copy data
kolom = 2
lijst = Workbooks(Name).Worksheets("Results").Range("B3: B10")

For Each Scenario In lijst
kolom = kolom + 6
Scenario = Worksheets(current).Range(kolom & 1).Value

ThisWorkbook.Worksheets(current).Range("B" & Row).Value = Application.WorksheetFunction.VLookup(Scenario, Workbooks(Name).Worksheets("Results").Range("B3: AC10"), 3, False)
ThisWorkbook.Worksheets(current).Range("C" & Row).Value = Application.WorksheetFunction.VLookup(Scenario, Workbooks(Name).Worksheets("Results").Range("B3: AC10"), 7, False)
ThisWorkbook.Worksheets(current).Range("D" & Row).Value = Application.WorksheetFunction.VLookup(Scenario, Workbooks(Name).Worksheets("Results").Range("B3: AC10"), 11, False)

ThisWorkbook.Worksheets(current).Range("E" & Row).Value = Application.WorksheetFunction.VLookup(Scenario, Workbooks(Name).Worksheets("Results").Range("B3: AC10"), 21, False)
ThisWorkbook.Worksheets(current).Range("F" & Row).Value = Application.WorksheetFunction.VLookup(Scenario, Workbooks(Name).Worksheets("Results").Range("B3: AC10"), 25, False)
ThisWorkbook.Worksheets(current).Range("G" & Row).Value = Application.WorksheetFunction.VLookup(Scenario, Workbooks(Name).Worksheets("Results").Range("B3: AC10"), 29, False)
Next Scenario

Workbooks(Name).Close False
Next file

MsgBox "There were " & c & " file(s) found."

Set file = Nothing
Set folder = Nothing
Set fso = Nothing

End Sub

I'm having trouble with the Name-variable in the 'red line'. This variable is set in the 'purple lines' however, the code (which I got online) keeps adding ".pdf" to the name.

I think it has to do with the settings of the 'purple/underlined line' but I don't know if this is true and if so, how to change it. Can you help me?

thanks in advance!

Schzuki
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi,

I am in a bit of a hurry so I hope this works ok.

The first file it is coming across in the selected folder must be a .pdf file?
You need to filter out the .xls files in the selected folder for opening.
So we take each filename, extract the extension and compare it to ".xls" if it is correct we open the file otherwise we move onto the next.

FoldPath is the Path
Name is the filename including the extension.



Code:
For Each file In folder.Files
    c = c + 1
Name = file.Name

Ext = Right(Name, 4)  'gets the extension including dot. If you didn't include the dot the InStr check would also open .xlsm, .xlsx files found
If InStr(Ext, ".xls") Then


Workbooks.Open Filename:=FldPath & "\" & Name

....rest of code


Workbooks(Name).Close False
End If
Next file
 
Upvote 0
that's not really the problem. But while I was going over things I found a mistake in the way I selected my path. (which solved my problem)
sorry for wasting your time, my bad!

Thanks for the reaction nonetheless!
 
Upvote 0

Forum statistics

Threads
1,203,388
Messages
6,055,129
Members
444,763
Latest member
Jaapaap

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