Hello, I am trying to move a group of worksheets to a new workbook. I have the code working when I hard code the worksheet names in the code, but I want to make those variables that will be filled by values on one of the worksheets, so that this can be run for different groups.
This is the original code that works;
This is the code that I have incorporated it into, where I build the array based on the team selected;
I'm not sure what the proper syntax is to use the Managers() array, do I need to write another loop, or is there another way to just say use everything in here?
This is the original code that works;
Code:
Sub Seperate_Sheets()
Dim Path1 As String
Path1 = ActiveWorkbook.Path & "\" & "Tracker 1"
Sheets(Array("sheet1", "sheet2", "sheet3")).Move
ActiveWorkbook.SaveAs Filename:=Path1, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
End Sub
This is the code that I have incorporated it into, where I build the array based on the team selected;
Code:
Sub newMovement()
Dim ExDir As String
Dim Managers() As String
Dim MgrCount As Integer
Dim r As Integer, lr As Integer, ldir As Integer, o As Integer
o = 1
lr = Sheets("Swap").UsedRange.Rows.Count
ldir = Sheets("Directory").UsedRange.Rows.Count
ExDir = Sheets("Control").Range("A2").Value
MgrCount = 0
'determing how many managers are on each team
For r = 2 To lr
If ExDir = Sheets("Swap").Range("A" & r).Value Then
MgrCount = Sheets("Swap").Range("b" & r).Value
End If
Next r
'size array
ReDim Managers(MgrCount) As String
'build list of managers on selected team
For r = 1 To ldir
If Sheets("Directory").Range("h" & r).Value = ExDir Then
Managers(o) = Sheets("Directory").Range("a" & r).Value
o = o + 1
End If
Next r
'move report tabs to new workbook
Sheets(array(Managers()).Move
ActiveWorkbook.SaveAs Filename:=Path1, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
End Sub
I'm not sure what the proper syntax is to use the Managers() array, do I need to write another loop, or is there another way to just say use everything in here?