Hi all, I have the current code set up with variable options on a masterlist. How do I make the macro to run for all variables? Thanks In advance for help, macro_ -
Code:
'==========>>
Option Explicit
'---------->>
Public Sub PassVariables()
Dim WB As Workbook
Dim SH As Worksheet
Set WB = ThisWorkbook
Set SH = WB.Sheets("Sheet1")
With SH
Call Main(myYear:=.Range("A2").Value, _
myQuarter:=CStr(.Range("B2").Value), _
myFolder:=CStr(.Range("C2").Value), _
mySaveAsFolder:=CStr(.Range("D2").Value), _
mySaveAsName:=CStr(.Range("E2").Value), _
blCreateFolder:=CStr(.Range("F2").Value))
End With
End Sub '---------->>
Public Sub Main(myYear As Variant, myQuarter As String, _
myFolder As String, _
mySaveAsFolder As String, _
mySaveAsName As String, _
blCreateFolder As String)
Dim WB As Workbook
Dim WS As Worksheet
Dim spath As String
Dim sSaveAsPath As String
Dim sFilename As String
Dim sFullname As String
Dim aStr As String
aStr = myQuarter & " " & myYear
spath = "X:\specific folder\" _
& myYear & "\" & aStr & "\TMT\" & myFolder
sSaveAsPath = "X:\specific folder\" & myYear & "\" _
& aStr & "\TMT\" _
& mySaveAsFolder
sFilename = "ST " & aStr & ".xlsm"
sFullname = spath & "\" & sFilename
ChDir spath
Workbooks.Open Filename:=sFullname, Updatelinks:=0
Set WS = ActiveSheet
Set WB = Workbooks.Add(xlWBATWorksheet)
WS.Range("A1:S84").Copy
WB.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
If blCreateFolder Then
MkDir sSaveAsPath
End If
ChDir sSaveAsPath
ActiveWorkbook.SaveAs Filename:=sSaveAsPath & "\" & mySaveAsName, _
FileFormat:=xlOpenXMLWorkbook, _
CreateBackup:=False
End Sub
'<<==========