dipitiduda2
Technical User
Hello,
Working in Excel XP and need assistance with VB coding listed below. Trying to copy the ActiveSheet and rename the sucessive sheets.
VB gives me a 'Run-time error' that says, "Cannot rename a sheet to the same name as another sheet, a referenced object library or a workbook reference by Visual Basic".
Now, if I cannot rename a sheet - "Adjustment 1" copied to "Adjustment 1(2)" - to the same name as the previous sheet, what code do I use?
What I need is for the first copied sheet to be named "Adjustment 1", the second sheet to be named "Adjustment 2", the third to "Adjustment 3", etc.
Private Sub cmdAdjustment_Add_Btn_Click()
ActiveSheet.Unprotect
MsgBox ".......", vbYes, "Add an Adjustment"
ActiveSheet.Copy after:=ActiveSheet
ActiveSheet.Name = "Adjustment 1"
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
MsgBox "......", vbExclamation, "Warning!"
End Sub
Thank you!
Working in Excel XP and need assistance with VB coding listed below. Trying to copy the ActiveSheet and rename the sucessive sheets.
VB gives me a 'Run-time error' that says, "Cannot rename a sheet to the same name as another sheet, a referenced object library or a workbook reference by Visual Basic".
Now, if I cannot rename a sheet - "Adjustment 1" copied to "Adjustment 1(2)" - to the same name as the previous sheet, what code do I use?
What I need is for the first copied sheet to be named "Adjustment 1", the second sheet to be named "Adjustment 2", the third to "Adjustment 3", etc.
Private Sub cmdAdjustment_Add_Btn_Click()
ActiveSheet.Unprotect
MsgBox ".......", vbYes, "Add an Adjustment"
ActiveSheet.Copy after:=ActiveSheet
ActiveSheet.Name = "Adjustment 1"
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
MsgBox "......", vbExclamation, "Warning!"
End Sub
Thank you!