I want to consolidate data from one workbook into another. I am using option buttons to get the file names, and a command button 'MergeCBtn' to perform the consolidation. If I have all the sheets in the same workbook, I have written a macro that can do this without using the option buttons, and it works OK. But if I try to consolidate from different workbooks, using the format below I get 'Subscript out of range'.
Does Consolidate only work with sheets in the same workbook?
Advice appreciated,
Private Sub MergeCBtn_Click()
If JanBtn.Value = True Then strMnthBtn = "jan"
If CommsBtn.Value = True Then strFilesBtn = "Filename_"
strMasterfile = "MasterFile.xls"
strMergefile = "MergeFile" & strFilesBtn & strMnthBtn
Workbooks.Open Filename:=strMasterfile
Workbooks.Open Filename:=strMergefile
Worksheets(strMasterfile).Range("F45").Consolidate _
Sources:=Array(strMergefile &"!R45C6:R48C6"), _
Function:=xlSum
End Sub
Does Consolidate only work with sheets in the same workbook?
Advice appreciated,
Private Sub MergeCBtn_Click()
If JanBtn.Value = True Then strMnthBtn = "jan"
If CommsBtn.Value = True Then strFilesBtn = "Filename_"
strMasterfile = "MasterFile.xls"
strMergefile = "MergeFile" & strFilesBtn & strMnthBtn
Workbooks.Open Filename:=strMasterfile
Workbooks.Open Filename:=strMergefile
Worksheets(strMasterfile).Range("F45").Consolidate _
Sources:=Array(strMergefile &"!R45C6:R48C6"), _
Function:=xlSum
End Sub