Hi all - I'm trying to get a macro to copy sheets from other workbooks based on inputs in a "setup" tab. The sheet names are the same for each workbook, and I would like the VBA formula to reference a single cell input by the user.
For example, my current formula is:
Application.DisplayAlerts = False
Dim wkbk As Workbook
Set wkbk = ActiveWorkbook
WS_Count = ActiveWorkbook.Worksheets.Count
For j = 2 To WS_Count
ActiveWorkbook.Worksheets(WS_Count - j + 2).Delete
Next j
For i = 1 To 12
thepath = ActiveWorkbook.Sheets("Setup").Cells(i, 1).Value
Workbooks.Open Filename:=thepath, UpdateLinks:=0
Select Case i
Case 1
Sheets("XX").Copy After:=wkbk.Sheets(wkbk.Worksheets.Count)
Case 2
Sheets("XX").Copy After:=wkbk.Sheets(wkbk.Worksheets.Count)
I have 12 cases for monthly workbooks. In the last lines, "XX" is the tab name that I would like to have referenced to a cell in the active setup workbook that is receiving the copied sheets. How can I modify this to reference inputs in a cell? Bonus, if you know how to close the workbook that I currently have opening from the set file path inputs, that would be save me the second macro (which would also likely need to reference cells in my setup tab).
Thank you all in advance!
For example, my current formula is:
Application.DisplayAlerts = False
Dim wkbk As Workbook
Set wkbk = ActiveWorkbook
WS_Count = ActiveWorkbook.Worksheets.Count
For j = 2 To WS_Count
ActiveWorkbook.Worksheets(WS_Count - j + 2).Delete
Next j
For i = 1 To 12
thepath = ActiveWorkbook.Sheets("Setup").Cells(i, 1).Value
Workbooks.Open Filename:=thepath, UpdateLinks:=0
Select Case i
Case 1
Sheets("XX").Copy After:=wkbk.Sheets(wkbk.Worksheets.Count)
Case 2
Sheets("XX").Copy After:=wkbk.Sheets(wkbk.Worksheets.Count)
I have 12 cases for monthly workbooks. In the last lines, "XX" is the tab name that I would like to have referenced to a cell in the active setup workbook that is receiving the copied sheets. How can I modify this to reference inputs in a cell? Bonus, if you know how to close the workbook that I currently have opening from the set file path inputs, that would be save me the second macro (which would also likely need to reference cells in my setup tab).
Thank you all in advance!