Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Consolidation using Option Buttons for workbook names

Status
Not open for further replies.

Lesgaz

Technical User
Feb 24, 2002
1
GB
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top