Public Sub MyMacro(ByVal argJump As String)
If argJump="TOP" Then
' do one part of the macro
End If
If argJump="OTHER" Then
' do another part of the macro
End If
End Sub
You would have to tell your second macro that you want execution to start somewhere other than at the beginning.
Do you always want to start the second macro somewhere other than the beginning or do you sometimes want it to start executing at the beginning?
You can design your second macro like this:-
Then you can control where you want execution to start by calling it as Call MyMacro("TOP") or Call MyMacro("OTHER"), etc.Code:Public Sub MyMacro(ByVal argJump As String) If argJump="TOP" Then ' do one part of the macro End If If argJump="OTHER" Then ' do another part of the macro End If End Sub
However be aware that when you Call another macro, when it finishes, control returns to the statement after the original Call statement.
They way it's written, you have to supply an argument, even if it's an empty string.
But you're making it more complicated than it should be. The question is; what is it that calls MyMacro when the user form is complete? That's the place to decide what to do next. If the user clicks Cancel and you don't want to call MyMacro, don't call it - simple as that.
Perhaps this is the point at which you should post your code so that we can advise better. Please place it between CODE tags - the # icon in the advanced editor toolbar.
Private Sub CommandButton1_Click()
If Not (AllComboBoxesFilled()) Then
MsgBox "Please complete the form, all boxes are required.", vbInformation, "Update Store Hours"
Else
Application.ScreenUpdating = False
Dim ws As Worksheet, rngFind, rngRow As Range
Set ws = ThisWorkbook.Sheets("StoreHours")
StoreNumber = Worksheets("MyStoreInfo").Range("C2")
Set rngFind = ws.Range("C:C").Find(what:=StoreNumber, MatchCase:=True)
If Not rngFind Is Nothing Then
rngFind.Offset(0, 3).Value = Me.SundayOpen.Value
rngFind.Offset(0, 4).Value = Me.SundayClose.Value
rngFind.Offset(0, 5).Value = Me.MondayOpen.Value
rngFind.Offset(0, 6).Value = Me.MondayClose.Value
rngFind.Offset(0, 7).Value = Me.TuesdayOpen.Value
rngFind.Offset(0, 8).Value = Me.TuesdayClose.Value
rngFind.Offset(0, 9).Value = Me.WednesdayOpen.Value
rngFind.Offset(0, 10).Value = Me.WednesdayClose.Value
rngFind.Offset(0, 11).Value = Me.ThursdayOpen.Value
rngFind.Offset(0, 12).Value = Me.ThursdayClose.Value
rngFind.Offset(0, 13).Value = Me.FridayOpen.Value
rngFind.Offset(0, 14).Value = Me.FridayClose.Value
rngFind.Offset(0, 15).Value = Me.SaturdayOpen.Value
rngFind.Offset(0, 16).Value = Me.SaturdayClose.Value
rngFind.Offset(0, 17).Value = Me.Month.Value
rngFind.Offset(0, 18).Value = Me.Year.Value
MsgBox "Store Hours have been updated)", vbInformation, "Update Store Hours"
Application.ScreenUpdating = True
Else
MsgBox "Your Store Number is not input on the MY STORE INFO Tab", vbInformation, "Update Store Hours"
Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
Unload Me
Application.ScreenUpdating = True
End Sub
Public Sub GetCurrentSchedulingTemplate()
Dim wbThis As Workbook
Dim wbThat As Workbook
Dim ws As Worksheet
Dim x As Integer
Dim y As Integer
Dim Response As VbMsgBoxResult
Dim LR As Long, o As Long
StoreHours.Show 'update the store hours first :)
If SheetExists("Week 1") And SheetExists("Week 2") And SheetExists("Week 3") And SheetExists("Week 4") Then
Response = MsgBox("A scheduling template already exists, Press Yes to delete the old template and replace, or No to cancel and quit.", vbQuestion + _
vbYesNo)
If Response = vbYes Then
MsgBox "This can take up to a minute to talk with T-Mobile servers.", vbInformation, "WFM Tool"
Application.ScreenUpdating = False
With Sheets("WorksheetList")
LR = .Range("A" & Rows.Count).End(xlUp).Row
Application.DisplayAlerts = False
On Error Resume Next
For o = 1 To LR
Sheets(.Range("A" & o).Value).Delete
Next o
On Error GoTo 0
Application.DisplayAlerts = True
End With
Set wb = Workbooks.Open(Filename:="S:\WASeattle\WFM\Test\Retail Store Scheduling Template.xls")
Set i = ActiveWorkbook.Sheets
For Each sh In i
sh.Visible = True
Next
Windows("Retail Store Scheduling Template.xls").Activate
Sheets(Array("Month at a Glance", "Daily Budget for the Month", "Week 1", _
"Week 1 Chart", "Week 2", "Week 2 Chart", "Week 3", "Week 3 Chart", "Week 4", _
"Week 4 Chart", "Week 5", "Week 5 Chart", "Productivity Calendars", _
"Schedule at a Glance", "Peak Hours", "Productivity Calendar Mapping", _
"Peak Hr Daily Allocation", "Store Productivity Mapping", "Store Names", _
"Labor Budget")).Select
Sheets("Month at a Glance").Activate
Sheets(Array("Month at a Glance", "Daily Budget for the Month", "Week 1", _
"Week 1 Chart", "Week 2", "Week 2 Chart", "Week 3", "Week 3 Chart", "Week 4", _
"Week 4 Chart", "Week 5", "Week 5 Chart", "Productivity Calendars", _
"Schedule at a Glance", "Peak Hours", "Productivity Calendar Mapping", _
"Peak Hr Daily Allocation", "Store Productivity Mapping", "Store Names", _
"Labor Budget")).Copy After:=ThisWorkbook. _
Sheets(6)
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Schedule Dashboard" And ws.Name <> "Week 1" And ws.Name <> "Week 2" And ws.Name <> "Week 3" And ws.Name <> "Week 4" And ws.Name <> "Week 5" Then ws.Visible = xlSheetHidden
Next
Sheets("Schedule Tool").Visible = True
Sheets("Schedule Tool").Select
Range("A1").Select
Sheets("Schedule Dashboard").Select
Sheets("WorksheetList").Visible = True
Sheets("WorksheetList").Select
Cells.Select
Selection.ClearContents
Range("A1").Select
Sheets("WorksheetList").Select
Windows("Retail Store Scheduling Template.xls").Activate
With ThisWorkbook.Worksheets("WorksheetList")
.Range("A:A").ClearContents
For Each ws In ActiveWorkbook.Worksheets
y = y + 1
.Range("A" & y) = ws.Name
Next ws
End With
For Each WkbkName In Application.Workbooks()
If WkbkName.Name <> ThisWorkbook.Name Then WkbkName.Close WkbkName.Saved = False
Next
Sheets("WorksheetList").Visible = False
Sheets("Schedule Dashboard").Select
Range("D18").Select
Application.ScreenUpdating = True
MsgBox "Schedule template has been retrived. +1 for Doppke.", vbInformation, "Get Current Scheduling Template"
End If
Exit Sub
Else
MsgBox "This can take up to a minute to talk with T-Mobile servers.", vbInformation, "WFM Tool"
Application.ScreenUpdating = False
Set wb = Workbooks.Open(Filename:="S:\WASeattle\WFM\Test\Retail Store Scheduling Template.xls")
Set i = ActiveWorkbook.Sheets
For Each sh In i
sh.Visible = True
Next
Windows("Retail Store Scheduling Template.xls").Activate
Sheets(Array("Month at a Glance", "Daily Budget for the Month", "Week 1", _
"Week 1 Chart", "Week 2", "Week 2 Chart", "Week 3", "Week 3 Chart", "Week 4", _
"Week 4 Chart", "Week 5", "Week 5 Chart", "Productivity Calendars", _
"Schedule at a Glance", "Peak Hours", "Productivity Calendar Mapping", _
"Peak Hr Daily Allocation", "Store Productivity Mapping", "Store Names", _
"Labor Budget")).Select
Sheets("Month at a Glance").Activate
Sheets(Array("Month at a Glance", "Daily Budget for the Month", "Week 1", _
"Week 1 Chart", "Week 2", "Week 2 Chart", "Week 3", "Week 3 Chart", "Week 4", _
"Week 4 Chart", "Week 5", "Week 5 Chart", "Productivity Calendars", _
"Schedule at a Glance", "Peak Hours", "Productivity Calendar Mapping", _
"Peak Hr Daily Allocation", "Store Productivity Mapping", "Store Names", _
"Labor Budget")).Copy After:=ThisWorkbook. _
Sheets(6)
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Schedule Dashboard" And ws.Name <> "Week 1" And ws.Name <> "Week 2" And ws.Name <> "Week 3" And ws.Name <> "Week 4" And ws.Name <> "Week 5" Then ws.Visible = xlSheetHidden
Next
Sheets("Schedule Tool").Visible = True
Sheets("Schedule Tool").Select
Range("A1").Select
Sheets("Schedule Dashboard").Select
Sheets("WorksheetList").Visible = True
Sheets("WorksheetList").Select
Cells.Select
Selection.ClearContents
Range("A1").Select
Sheets("WorksheetList").Select
Windows("Retail Store Scheduling Template.xls").Activate
With ThisWorkbook.Worksheets("WorksheetList")
.Range("A:A").ClearContents
For Each ws In ActiveWorkbook.Worksheets
y = y + 1
.Range("A" & y) = ws.Name
Next ws
End With
For Each WkbkName In Application.Workbooks()
If WkbkName.Name <> ThisWorkbook.Name Then WkbkName.Close WkbkName.Saved = False
Next
Sheets("WorksheetList").Visible = False
Sheets("Schedule Dashboard").Select
Range("D18").Select
Application.ScreenUpdating = True
MsgBox "Schedule template has been retrived. +1 for Doppke.", vbInformation, "Get Current Scheduling Template"
End If
Exit Sub
End Sub
CommandButton1_Click() seems to be incomplete.
Maybe the best way of handling this is to declare a global variable (Public FormValid As Boolean in a general code module) which you set to False when the useform loads. At the end of your userform processing, if you have all the fields you need, set FormValid to True.
When you get back to GetCurrentSchedulingTemplate(), test FormValid: if it's True, continue with the processing; if it's False (indicating that not all the fields were completed properly), skip the processing or Exit Sub, whichever's the most appropriate.
Private Sub CommandButton1_Click()
If Not (AllComboBoxesFilled()) Then
MsgBox "Please complete the form, all boxes are required.", vbInformation, "Update Store Hours"
Else
Application.ScreenUpdating = False
Dim ws As Worksheet, rngFind, rngRow As Range
Set ws = ThisWorkbook.Sheets("StoreHours")
StoreNumber = Worksheets("MyStoreInfo").Range("C2")
Set rngFind = ws.Range("C:C").Find(what:=StoreNumber, MatchCase:=True)
If Not rngFind Is Nothing Then
rngFind.Offset(0, 3).Value = Me.SundayOpen.Value
rngFind.Offset(0, 4).Value = Me.SundayClose.Value
rngFind.Offset(0, 5).Value = Me.MondayOpen.Value
rngFind.Offset(0, 6).Value = Me.MondayClose.Value
rngFind.Offset(0, 7).Value = Me.TuesdayOpen.Value
rngFind.Offset(0, 8).Value = Me.TuesdayClose.Value
rngFind.Offset(0, 9).Value = Me.WednesdayOpen.Value
rngFind.Offset(0, 10).Value = Me.WednesdayClose.Value
rngFind.Offset(0, 11).Value = Me.ThursdayOpen.Value
rngFind.Offset(0, 12).Value = Me.ThursdayClose.Value
rngFind.Offset(0, 13).Value = Me.FridayOpen.Value
rngFind.Offset(0, 14).Value = Me.FridayClose.Value
rngFind.Offset(0, 15).Value = Me.SaturdayOpen.Value
rngFind.Offset(0, 16).Value = Me.SaturdayClose.Value
rngFind.Offset(0, 17).Value = Me.Month.Value
rngFind.Offset(0, 18).Value = Me.Year.Value
MsgBox "Store Hours have been updated)", vbInformation, "Update Store Hours"
Application.ScreenUpdating = True
Else
MsgBox "Your Store Number is not input on the MY STORE INFO Tab", vbInformation, "Update Store Hours"
End If
End If
End Sub
[B]Public FormValid As Boolean[/B]
Private Sub CommandButton1_Click()
Dim ws As Worksheet, rngFind [COLOR=red][B]As Range[/B][/COLOR], rngRow As Range
[COLOR=red][B]FormValid = False
Do Until FormValid
[/B][/COLOR] If Not AllComboBoxesFilled() Then
MsgBox "Please complete the form, all boxes are required.", vbExclamation, "Update Store Hours"
Else
Application.ScreenUpdating = False
Set ws = ThisWorkbook.Sheets("StoreHours")
StoreNumber = Worksheets("MyStoreInfo").Range("C2")
Set rngFind = ws.Range("C:C").Find(what:=StoreNumber, MatchCase:=True)
If Not rngFind Is Nothing Then
rngFind.Offset(0, 3).Value = Me.SundayOpen.Value
rngFind.Offset(0, 4).Value = Me.SundayClose.Value
rngFind.Offset(0, 5).Value = Me.MondayOpen.Value
rngFind.Offset(0, 6).Value = Me.MondayClose.Value
rngFind.Offset(0, 7).Value = Me.TuesdayOpen.Value
rngFind.Offset(0, 8).Value = Me.TuesdayClose.Value
rngFind.Offset(0, 9).Value = Me.WednesdayOpen.Value
rngFind.Offset(0, 10).Value = Me.WednesdayClose.Value
rngFind.Offset(0, 11).Value = Me.ThursdayOpen.Value
rngFind.Offset(0, 12).Value = Me.ThursdayClose.Value
rngFind.Offset(0, 13).Value = Me.FridayOpen.Value
rngFind.Offset(0, 14).Value = Me.FridayClose.Value
rngFind.Offset(0, 15).Value = Me.SaturdayOpen.Value
rngFind.Offset(0, 16).Value = Me.SaturdayClose.Value
rngFind.Offset(0, 17).Value = Me.Month.Value
rngFind.Offset(0, 18).Value = Me.Year.Value
MsgBox "Store Hours have been updated", vbInformation, "Update Store Hours"
Application.ScreenUpdating = True
[COLOR=red][B] FormValid = True[/B][/COLOR]
[COLOR=red][B] Unload Me
Exit Sub
[/B][/COLOR] Else
MsgBox "Your Store Number is not input on the MY STORE INFO Tab", vbInformation, "Update Store Hours"
End If
End If
[COLOR=red][B] Loop
[/B][/COLOR]
End Sub
Public Sub GetCurrentSchedulingTemplate()
Dim wbThis As Workbook
Dim wbThat As Workbook
Dim ws As Worksheet
Dim x As Integer
Dim y As Integer
Dim Response As VbMsgBoxResult
Dim LR As Long, o As Long
StoreHours.Show 'update the store hours first :)
If FormValid Then
' do something... the rest of GetCurrentSchedulingTemplate()?
Else
' do something if userform not correctly filled in...
End If
Public Sub GetCurrentSchedulingTemplate()
Dim wbThis As Workbook
Dim wbThat As Workbook
Dim ws As Worksheet
Dim x As Integer
Dim y As Integer
Dim Response As VbMsgBoxResult
Dim LR As Long, o As Long
StoreHours.Show 'update the store hours first :)
[B][COLOR=red] If Not FormValid Then Exit Sub
[/COLOR][/B]
If SheetExists("Week 1") And SheetExists("Week 2") And SheetExists("Week 3") And SheetExists("Week 4") Then
Response = MsgBox("A scheduling template already exists, Press Yes to delete the old template and replace, or No to cancel and quit.", _
vbQuestion + vbYesNo)
If Response = vbYes Then
MsgBox "This can take up to a minute to talk with T-Mobile servers.", vbInformation, "WFM Tool"
Application.ScreenUpdating = False
With Sheets("WorksheetList")
LR = .Range("A" & Rows.Count).End(xlUp).Row
Application.DisplayAlerts = False
On Error Resume Next
For o = 1 To LR
Sheets(.Range("A" & o).Value).Delete
Next o
On Error GoTo 0
Application.DisplayAlerts = True
End With
Set wb = Workbooks.Open(Filename:="S:\WASeattle\WFM\Test\Retail Store Scheduling Template.xls")
Set i = ActiveWorkbook.Sheets
For Each sh In i
sh.Visible = True
Next
Windows("Retail Store Scheduling Template.xls").Activate
Sheets(Array("Month at a Glance", "Daily Budget for the Month", "Week 1", _
"Week 1 Chart", "Week 2", "Week 2 Chart", "Week 3", "Week 3 Chart", "Week 4", _
"Week 4 Chart", "Week 5", "Week 5 Chart", "Productivity Calendars", _
"Schedule at a Glance", "Peak Hours", "Productivity Calendar Mapping", _
"Peak Hr Daily Allocation", "Store Productivity Mapping", "Store Names", _
"Labor Budget")).Select
Sheets("Month at a Glance").Activate
Sheets(Array("Month at a Glance", "Daily Budget for the Month", "Week 1", _
"Week 1 Chart", "Week 2", "Week 2 Chart", "Week 3", "Week 3 Chart", "Week 4", _
"Week 4 Chart", "Week 5", "Week 5 Chart", "Productivity Calendars", _
"Schedule at a Glance", "Peak Hours", "Productivity Calendar Mapping", _
"Peak Hr Daily Allocation", "Store Productivity Mapping", "Store Names", _
"Labor Budget")).Copy After:=ThisWorkbook. _
Sheets(6)
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Schedule Dashboard" And ws.Name <> "Week 1" And ws.Name <> "Week 2" And ws.Name <> "Week 3" And ws.Name <> "Week 4" And ws.Name <> "Week 5" Then ws.Visible = xlSheetHidden
Next
Sheets("Schedule Tool").Visible = True
Sheets("Schedule Tool").Select
Range("A1").Select
Sheets("Schedule Dashboard").Select
Sheets("WorksheetList").Visible = True
Sheets("WorksheetList").Select
Cells.Select
Selection.ClearContents
Range("A1").Select
Sheets("WorksheetList").Select
Windows("Retail Store Scheduling Template.xls").Activate
With ThisWorkbook.Worksheets("WorksheetList")
.Range("A:A").ClearContents
For Each ws In ActiveWorkbook.Worksheets
y = y + 1
.Range("A" & y) = ws.Name
Next ws
End With
For Each WkbkName In Application.Workbooks()
If WkbkName.Name <> ThisWorkbook.Name Then WkbkName.Close WkbkName.Saved = False
Next
Sheets("WorksheetList").Visible = False
Sheets("Schedule Dashboard").Select
Range("D18").Select
Application.ScreenUpdating = True
MsgBox "Schedule template has been retrived. +1 for Doppke.", vbInformation, "Get Current Scheduling Template"
End If
Exit Sub
Else
MsgBox "This can take up to a minute to talk with T-Mobile servers.", vbInformation, "WFM Tool"
Application.ScreenUpdating = False
Set wb = Workbooks.Open(Filename:="S:\WASeattle\WFM\Test\Retail Store Scheduling Template.xls")
Set i = ActiveWorkbook.Sheets
For Each sh In i
sh.Visible = True
Next
Windows("Retail Store Scheduling Template.xls").Activate
Sheets(Array("Month at a Glance", "Daily Budget for the Month", "Week 1", _
"Week 1 Chart", "Week 2", "Week 2 Chart", "Week 3", "Week 3 Chart", "Week 4", _
"Week 4 Chart", "Week 5", "Week 5 Chart", "Productivity Calendars", _
"Schedule at a Glance", "Peak Hours", "Productivity Calendar Mapping", _
"Peak Hr Daily Allocation", "Store Productivity Mapping", "Store Names", _
"Labor Budget")).Select
Sheets("Month at a Glance").Activate
Sheets(Array("Month at a Glance", "Daily Budget for the Month", "Week 1", _
"Week 1 Chart", "Week 2", "Week 2 Chart", "Week 3", "Week 3 Chart", "Week 4", _
"Week 4 Chart", "Week 5", "Week 5 Chart", "Productivity Calendars", _
"Schedule at a Glance", "Peak Hours", "Productivity Calendar Mapping", _
"Peak Hr Daily Allocation", "Store Productivity Mapping", "Store Names", _
"Labor Budget")).Copy After:=ThisWorkbook.Sheets(6)
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Schedule Dashboard" And ws.Name <> "Week 1" And ws.Name <> "Week 2" And ws.Name <> "Week 3" And ws.Name <> "Week 4" And ws.Name <> "Week 5" Then ws.Visible = xlSheetHidden
Next
Sheets("Schedule Tool").Visible = True
Sheets("Schedule Tool").Select
Range("A1").Select
Sheets("Schedule Dashboard").Select
Sheets("WorksheetList").Visible = True
Sheets("WorksheetList").Select
Cells.Select
Selection.ClearContents
Range("A1").Select
Sheets("WorksheetList").Select
Windows("Retail Store Scheduling Template.xls").Activate
With ThisWorkbook.Worksheets("WorksheetList")
.Range("A:A").ClearContents
For Each ws In ActiveWorkbook.Worksheets
y = y + 1
.Range("A" & y) = ws.Name
Next ws
End With
For Each WkbkName In Application.Workbooks()
If WkbkName.Name <> ThisWorkbook.Name Then WkbkName.Close WkbkName.Saved = False
Next
Sheets("WorksheetList").Visible = False
Sheets("Schedule Dashboard").Select
Range("D18").Select
Application.ScreenUpdating = True
MsgBox "Schedule template has been retrived. +1 for Doppke.", vbInformation, "Get Current Scheduling Template"
End If
End Sub
[B]Public FormValid As Boolean[/B]
Private Sub CommandButton1_Click()
Dim ws As Worksheet, rngFind [COLOR=red][B]As Range[/B][/COLOR], rngRow As Range
[COLOR=red][B]FormValid = False[/B][/COLOR]
[B][COLOR=red] Do Until FormValid[/COLOR][/B]
If Not AllComboBoxesFilled() Then
MsgBox "Please complete the form, all boxes are required.", vbExclamation, "Update Store Hours"
Else
Application.ScreenUpdating = False
Set ws = ThisWorkbook.Sheets("StoreHours")
StoreNumber = Worksheets("MyStoreInfo").Range("C2")
Set rngFind = ws.Range("C:C").Find(what:=StoreNumber, MatchCase:=True)
If Not rngFind Is Nothing Then
rngFind.Offset(0, 3).Value = Me.SundayOpen.Value
rngFind.Offset(0, 4).Value = Me.SundayClose.Value
rngFind.Offset(0, 5).Value = Me.MondayOpen.Value
rngFind.Offset(0, 6).Value = Me.MondayClose.Value
rngFind.Offset(0, 7).Value = Me.TuesdayOpen.Value
rngFind.Offset(0, 8).Value = Me.TuesdayClose.Value
rngFind.Offset(0, 9).Value = Me.WednesdayOpen.Value
rngFind.Offset(0, 10).Value = Me.WednesdayClose.Value
rngFind.Offset(0, 11).Value = Me.ThursdayOpen.Value
rngFind.Offset(0, 12).Value = Me.ThursdayClose.Value
rngFind.Offset(0, 13).Value = Me.FridayOpen.Value
rngFind.Offset(0, 14).Value = Me.FridayClose.Value
rngFind.Offset(0, 15).Value = Me.SaturdayOpen.Value
rngFind.Offset(0, 16).Value = Me.SaturdayClose.Value
rngFind.Offset(0, 17).Value = Me.Month.Value
rngFind.Offset(0, 18).Value = Me.Year.Value
MsgBox "Store Hours have been updated", vbInformation, "Update Store Hours"
Application.ScreenUpdating = True
[COLOR=red][B] FormValid = True[/B][/COLOR]
[COLOR=red][B] Unload Me[/B][/COLOR]
[B][COLOR=red] Exit Sub[/COLOR][/B]
Else
MsgBox "Your Store Number is not input on the MY STORE INFO Tab", vbInformation, "Update Store Hours"
End If
End If
[COLOR=red][B] Loop[/B][/COLOR]
End Sub
Public Sub GetCurrentSchedulingTemplate()
Dim wbThis As Workbook
Dim wbThat As Workbook
Dim ws As Worksheet
Dim x As Integer
Dim y As Integer
Dim Response As VbMsgBoxResult
Dim LR As Long, o As Long
StoreHours.Show 'update the store hours first :)
If FormValid Then
' do something... the rest of GetCurrentSchedulingTemplate()?
Else
' do something if userform not correctly filled in...
End If
Public Sub GetCurrentSchedulingTemplate()
Dim wbThis As Workbook
Dim wbThat As Workbook
Dim ws As Worksheet
Dim x As Integer
Dim y As Integer
Dim Response As VbMsgBoxResult
Dim LR As Long, o As Long
StoreHours.Show 'update the store hours first :)
If FormValid Then
' do something... the rest of GetCurrentSchedulingTemplate()?
If SheetExists("Week 1") And SheetExists("Week 2") And SheetExists("Week 3") And SheetExists("Week 4") Then
Response = MsgBox("A scheduling template already exists, Press Yes to delete the old template and replace, or No to cancel and quit.", _
vbQuestion + vbYesNo)
If Response = vbYes Then
MsgBox "This can take up to a minute to talk with T-Mobile servers.", vbInformation, "WFM Tool"
Application.ScreenUpdating = False
With Sheets("WorksheetList")
LR = .Range("A" & Rows.Count).End(xlUp).Row
Application.DisplayAlerts = False
On Error Resume Next
For o = 1 To LR
Sheets(.Range("A" & o).Value).Delete
Next o
On Error GoTo 0
Application.DisplayAlerts = True
End With
Set wb = Workbooks.Open(Filename:="S:\WASeattle\WFM\Test\Retail Store Scheduling Template.xls")
Set i = ActiveWorkbook.Sheets
For Each sh In i
sh.Visible = True
Next
Windows("Retail Store Scheduling Template.xls").Activate
Sheets(Array("Month at a Glance", "Daily Budget for the Month", "Week 1", _
"Week 1 Chart", "Week 2", "Week 2 Chart", "Week 3", "Week 3 Chart", "Week 4", _
"Week 4 Chart", "Week 5", "Week 5 Chart", "Productivity Calendars", _
"Schedule at a Glance", "Peak Hours", "Productivity Calendar Mapping", _
"Peak Hr Daily Allocation", "Store Productivity Mapping", "Store Names", _
"Labor Budget")).Select
Sheets("Month at a Glance").Activate
Sheets(Array("Month at a Glance", "Daily Budget for the Month", "Week 1", _
"Week 1 Chart", "Week 2", "Week 2 Chart", "Week 3", "Week 3 Chart", "Week 4", _
"Week 4 Chart", "Week 5", "Week 5 Chart", "Productivity Calendars", _
"Schedule at a Glance", "Peak Hours", "Productivity Calendar Mapping", _
"Peak Hr Daily Allocation", "Store Productivity Mapping", "Store Names", _
"Labor Budget")).Copy After:=ThisWorkbook. _
Sheets(6)
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Schedule Dashboard" And ws.Name <> "Week 1" And ws.Name <> "Week 2" And ws.Name <> "Week 3" And ws.Name <> "Week 4" And ws.Name <> "Week 5" Then ws.Visible = xlSheetHidden
Next
Sheets("Schedule Tool").Visible = True
Sheets("Schedule Tool").Select
Range("A1").Select
Sheets("Schedule Dashboard").Select
Sheets("WorksheetList").Visible = True
Sheets("WorksheetList").Select
Cells.Select
Selection.ClearContents
Range("A1").Select
Sheets("WorksheetList").Select
Windows("Retail Store Scheduling Template.xls").Activate
With ThisWorkbook.Worksheets("WorksheetList")
.Range("A:A").ClearContents
For Each ws In ActiveWorkbook.Worksheets
y = y + 1
.Range("A" & y) = ws.Name
Next ws
End With
For Each WkbkName In Application.Workbooks()
If WkbkName.Name <> ThisWorkbook.Name Then WkbkName.Close WkbkName.Saved = False
Next
Sheets("WorksheetList").Visible = False
Sheets("Schedule Dashboard").Select
Range("D18").Select
Application.ScreenUpdating = True
MsgBox "Schedule template has been retrived. +1 for Doppke.", vbInformation, "Get Current Scheduling Template"
End If
Exit Sub
Else
MsgBox "This can take up to a minute to talk with T-Mobile servers.", vbInformation, "WFM Tool"
Application.ScreenUpdating = False
Set wb = Workbooks.Open(Filename:="S:\WASeattle\WFM\Test\Retail Store Scheduling Template.xls")
Set i = ActiveWorkbook.Sheets
For Each sh In i
sh.Visible = True
Next
Windows("Retail Store Scheduling Template.xls").Activate
Sheets(Array("Month at a Glance", "Daily Budget for the Month", "Week 1", _
"Week 1 Chart", "Week 2", "Week 2 Chart", "Week 3", "Week 3 Chart", "Week 4", _
"Week 4 Chart", "Week 5", "Week 5 Chart", "Productivity Calendars", _
"Schedule at a Glance", "Peak Hours", "Productivity Calendar Mapping", _
"Peak Hr Daily Allocation", "Store Productivity Mapping", "Store Names", _
"Labor Budget")).Select
Sheets("Month at a Glance").Activate
Sheets(Array("Month at a Glance", "Daily Budget for the Month", "Week 1", _
"Week 1 Chart", "Week 2", "Week 2 Chart", "Week 3", "Week 3 Chart", "Week 4", _
"Week 4 Chart", "Week 5", "Week 5 Chart", "Productivity Calendars", _
"Schedule at a Glance", "Peak Hours", "Productivity Calendar Mapping", _
"Peak Hr Daily Allocation", "Store Productivity Mapping", "Store Names", _
"Labor Budget")).Copy After:=ThisWorkbook.Sheets(6)
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Schedule Dashboard" And ws.Name <> "Week 1" And ws.Name <> "Week 2" And ws.Name <> "Week 3" And ws.Name <> "Week 4" And ws.Name <> "Week 5" Then ws.Visible = xlSheetHidden
Next
Sheets("Schedule Tool").Visible = True
Sheets("Schedule Tool").Select
Range("A1").Select
Sheets("Schedule Dashboard").Select
Sheets("WorksheetList").Visible = True
Sheets("WorksheetList").Select
Cells.Select
Selection.ClearContents
Range("A1").Select
Sheets("WorksheetList").Select
Windows("Retail Store Scheduling Template.xls").Activate
With ThisWorkbook.Worksheets("WorksheetList")
.Range("A:A").ClearContents
For Each ws In ActiveWorkbook.Worksheets
y = y + 1
.Range("A" & y) = ws.Name
Next ws
End With
For Each WkbkName In Application.Workbooks()
If WkbkName.Name <> ThisWorkbook.Name Then WkbkName.Close WkbkName.Saved = False
Next
Sheets("WorksheetList").Visible = False
Sheets("Schedule Dashboard").Select
Range("D18").Select
Application.ScreenUpdating = True
MsgBox "Schedule template has been retrived. +1 for Doppke.", vbInformation, "Get Current Scheduling Template"
End If
Else
' do something if userform not correctly filled in...
MsgBox "This form needs to be filled out completely before submitting", vbInformation, "Update Store Hours"
End If
End Sub
Function AllComboBoxesFilled() As Boolean
Dim oneCB As Object
AllComboBoxesFilled = True
For Each oneCB In Me.Controls
If TypeName(oneCB) = "ComboBox" Then
AllComboBoxesFilled = AllComboBoxesFilled And (oneCB.Text <> vbNullString)
End If
Next oneCB
End Function