Greetings;
While I fully understand WHY the macro's are failing after I renamed the worksheet (making cloned worksheets with employees names as sheet names)
I have yet to figure out a way to make the macro reference the new sheet.
I am using a command button on the Cloned sheets;
Private Sub HideME()
'Hide all columns then exposes only the identified columns from the options buttons
ThisWorkbook.Sheets("MASTER BLANK").Columns("Q:GZ").EntireColumn.Hidden = True
ThisWorkbook.Sheets("MASTER BLANK").Columns(ColA & ":" & ColB).EntireColumn.Hidden = False
ScrollCentre
End Sub
Private Sub OptionButton1_Click()
'Apr
ColA = "Q"
ColB = "AF"
HideME
End Sub
Private Sub OptionButton2_Click()
'May()
ColA = "AG"
ColB = "AV"
HideME
End Sub
to allow the user to hide different parts of the sheet depending on the OptionButtonx_Click() is used.
Now these macros had been created on the "Master Blank" sheet with command button and then they are carried to the copied sheet using another macro on the MASTER EDIT sheet;
Private Sub CommandButton1_Click()
'Sub CopyMe()
Dim i As Long, LR As Long
Dim eName As String
Dim ws As Worksheet '
Dim wSht As Worksheet
Dim MyRng As Range
Dim cel As Range
Dim eRank As String
Application.ScreenUpdating = False
LR = ThisWorkbook.Sheets("MASTER EDIT").Range("C" & Rows.Count).End(xlUp).Row
For i = 4 To LR
eName = ThisWorkbook.Sheets("MASTER EDIT").Range("C" & i).Value
eRank = ThisWorkbook.Sheets("MASTER EDIT").Range("B" & i).Value
'reset variable
Set ws = Nothing
'check if the worksheet name is used by
'attempting to set worksheet to variable
On Error Resume Next
Set ws = Sheets(eName)
On Error GoTo 0
'if ws returns "nothing", sheet name is not used
If ws Is Nothing Then
'add new sheet with name in cell
ThisWorkbook.Sheets("Master Blank").Copy After:=Sheets(Sheets.Count)
ThisWorkbook.Sheets("Master Blank (2)").Name = eName
'Now send to formatting macro for names cell ref's
GoTo Formatter:
Else 'if sheet already exists
'display msgbox--if 'Yes' selected
If MsgBox(eName & " THIS SHEET ALREADY EXISTS!" & vbCrLf & _
"Over Writing will delete any existing data for this tech?", _
vbYesNo) = vbYes Then
'delete existing sheet
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
'add new sheet with name in cell
ThisWorkbook.Sheets("Master Blank").Copy After:=Sheets(Sheets.Count)
ThisWorkbook.Sheets("Master Blank (2)").Name = eName
'now send this to formatting macro for names cell ref's
GoTo Formatter:
End If
End If
Next i
Formatter:
Set wSht = ThisWorkbook.Sheets(eName)
Set MyRng = wSht.Range("A1,R1,AH1,AX1,BN1,CD1,CT1,DJ1,DZ1,EP1,FF1,FV1,GL1")
For Each cel In MyRng
cel.Value = eRank & " " & eName
Next cel
Application.ScreenUpdating = True
End Sub
How would I change the HideME() private sub to adopt the eName during its creation for the "Master Blank" identities in the sub?
Cheers
Aurbo99
Bookmarks