Hi,
I use a worksheet where I reconcile data from different reports. All repports have only 1 worksheet and use the same format.
VBA uses GetiOpenFilename with Multiselect enabled so ultimately, I would like Excel to import data from 1 workbook at the time and then continue with the following one from next empty row onwards.
My feeling is that there is something I do wrong with the loop and more specifically with ranges (hence the error message I keep getting "Subscript Out of Range")
Would be most grateful if someone could have a look !
Sub UnaVistaReports()
Dim Reports As Variant
Dim Report As Variant
Dim wsTo As Worksheet
Dim ActivelistWB As Workbook
Set wsTo = Sheets("UnaVista Data")
last = Sheets("UnaVista Data").Range("C" & Rows.Count).End(xlUp).Row
Reports = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*),*.xls*", _
Title:="Select Active List to Import", _
MultiSelect:=True)
If VarType(Reports) = vbBoolean Then
If Not Report Then Exit Sub
End If
For Each Report In Reports
Set ActivelistWB = Workbooks.Open(Report)
ActivelistWB.Sheets(1).UsedRange.Copy
wsTo.Range("C4").PasteSpecial xlPasteValues
ActivelistWB.Close False
Next Report
End Sub
I use a worksheet where I reconcile data from different reports. All repports have only 1 worksheet and use the same format.
VBA uses GetiOpenFilename with Multiselect enabled so ultimately, I would like Excel to import data from 1 workbook at the time and then continue with the following one from next empty row onwards.
My feeling is that there is something I do wrong with the loop and more specifically with ranges (hence the error message I keep getting "Subscript Out of Range")
Would be most grateful if someone could have a look !
Sub UnaVistaReports()
Dim Reports As Variant
Dim Report As Variant
Dim wsTo As Worksheet
Dim ActivelistWB As Workbook
Set wsTo = Sheets("UnaVista Data")
last = Sheets("UnaVista Data").Range("C" & Rows.Count).End(xlUp).Row
Reports = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*),*.xls*", _
Title:="Select Active List to Import", _
MultiSelect:=True)
If VarType(Reports) = vbBoolean Then
If Not Report Then Exit Sub
End If
For Each Report In Reports
Set ActivelistWB = Workbooks.Open(Report)
ActivelistWB.Sheets(1).UsedRange.Copy
wsTo.Range("C4").PasteSpecial xlPasteValues
ActivelistWB.Close False
Next Report
End Sub