Hi, I wonder whether someone may be able to help me please.
I'm using the code below to allow the user to select multiple Excel files, copy a range of data before amalgamating them into a 'Master' spreadsheet.
The problem I'm having is that out of the 'Source' workbooks there is only one sheet that I need to copy the information from, in this case it is called 'Combined'.
With the little knowledge I have I've tried to incorporate this by dding the 'SourceSheet' variable, but unfortunately when I run this I receive the following error:
Run-time error '424': Object required, and this line is highlighted as the source of the problem 'SourceSheet.Select'.
I just wondered whether someone may be able to take a look at this please and let me know where I'm going wrong?
Many thanks and kind regards
I'm using the code below to allow the user to select multiple Excel files, copy a range of data before amalgamating them into a 'Master' spreadsheet.
Code:
Sub BigMerge()
Set DestWB = ActiveWorkbook
SourceSheet = "Combined"
StartRow = 5
FileNames = Application.GetOpenFilename( _
filefilter:="Excel Files (*.xls*),*.xls*", _
Title:="Select the workbooks to merge.", MultiSelect:=True)
If IsArray(FileNames) = False Then
If FileNames = False Then
Exit Sub
End If
End If
For N = LBound(FileNames) To UBound(FileNames)
Set WB = Workbooks.Open(Filename:=FileNames(N), ReadOnly:=True)
For Each WS In WB.Worksheets
With WS
If .UsedRange.Cells.Count > 1 Then
dr = DestWB.Worksheets("Combined").Range("A" & Rows.Count).End(xlUp).Row + 1
Lastrow = .Range("A" & Rows.Count).End(xlUp).Row
SourceSheet.Select
.Range("A" & StartRow & ":AD" & Lastrow).Copy
DestWB.Worksheets("Combined").Cells(dr, "A").PasteSpecial _
Paste:=xlPasteValues, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=False
Application.CutCopyMode = False
End If
End With
Next WS
WB.Close savechanges:=False
Next N
End Sub
The problem I'm having is that out of the 'Source' workbooks there is only one sheet that I need to copy the information from, in this case it is called 'Combined'.
With the little knowledge I have I've tried to incorporate this by dding the 'SourceSheet' variable, but unfortunately when I run this I receive the following error:
Run-time error '424': Object required, and this line is highlighted as the source of the problem 'SourceSheet.Select'.
I just wondered whether someone may be able to take a look at this please and let me know where I'm going wrong?
Many thanks and kind regards