Hello, I have created 3 Macros that I have combined into a macro button - but I wanted to see if there is a way to "combine them" into one sub and make things more efficient, keeping the same order. Unfortunately, I am somewhat of a novice so I am not sure how to go about this. Any assistance would be much appreciated.
Logic:
Macro Button:
MACRO 1:
MACRO 2:
MACRO 3:
Logic:
- Initiate msg box. If no, exit. If yes, delete all sheets beginning with "Labor BOE"
- Copy template multiple times, name/number them sequentially (Labor BOE 1 of 2, Labor BOE 2 of 2...()
- Copy paste value in cell A1, then display Msg Box "BOE Generation Complete"
Macro Button:
Code:
Sub GenerateBOEs_Button()
GenerateBOEs_1
GenerateBOEs_2
GenerateBOEs_3
End Sub
MACRO 1:
Code:
Sub GenerateBOEs_1()
If MsgBox("Do you want to generate BOEs?" & Chr(10) & Chr(10) & "Warning: All existing BOEs will be deleted! This action cannot be undone!", vbYesNo, "Confirm") = vbYes Then
Application.DisplayAlerts = False
On Error Resume Next
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Sheets
If Left(sh.name, 9) = "Labor BOE" Then
sh.Delete
End If
Next sh
Application.DisplayAlerts = True
On Error GoTo 0
End If
End Sub
MACRO 2:
Code:
Sub GenerateBOEs_2()
Dim i As Integer
Dim i2 As Integer
Dim sh As Worksheet
' Set the worksheet to copy
Set sh = Worksheets("Template")
' Get the number of sheets to copy
i = Worksheets("Staffing Plan").Range("C5")
' Say how you want to name the first sheet
sh.name = "Template"
i2 = ActiveWorkbook.Worksheets.Count
For X = 1 To i
sh.Copy After:=Sheets(i2 + X - 1)
' Say how you want to name subsequent sheets
Sheets(X + i2).name = "Labor BOE " & X & " of " & i
Next X
End Sub
MACRO 3:
Code:
Sub GenerateBOEs_3()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
If Left(sh.name, 9) = "Labor BOE" Then
sh.Select
With sh.Range("A1")
.Value = .Value
End With
End If
Application.CutCopyMode = False
Next sh
MsgBox "BOE Generation Complete"
End Sub