Private Sub cmdAddSheets_Click()'dim variablesDim x As IntegerDim y As IntegerDim z As Integer'set error handlerOn Error GoTo Copier_Error'turn off screen updating and calculationApplication.ScreenUpdating = FalseApplication.Calculation = xlCalculationManual'check if the workbook isshared and exit if it isIf ThisWorkbook.MultiUserEditing ThenMsgBox "Please Unshare the workbook before you proceed"Exit SubEnd If'check that all values are in the userformIf Me.txtName = "" Or Me.cboNum = "" Or Me.cboNumSt = "" ThenMsgBox "You forgot to add the parematers for the sheet name."Exit SubEnd If'protect_allProtect_All'set variables for number of sheetx = Me.cboNum.Value'set variable for sheet name prefixy = Me.cboNumSt.Valuez = x + y – 1'check the first sheet nameNewName = Sheet1.Range("A4")'loop through to checkFor Each sh In ThisWorkbook.WorksheetsIf sh.Name = NewName ThenMsgBox "This information already exists.You are not permitted to copy over it"'if sheet name exists then got to end of subGoTo Copier_Error:End IfNext'run loop to add sheetsFor numtimes = y To zSheet3.Copy after:=Worksheets(Worksheets.Count)'create the new sheet nameActiveSheet.Name = Me.txtName & numtimesNext'return to Interface sheetSheet1.Select'list workshhet names on the interfaceListWorkSheetNames'turn of screen updating and calculationApplication.ScreenUpdating = TrueApplication.Calculation = xlCalculationAutomatic'error handlerOn Error GoTo 0Exit SubCopier_Error:'message if sheet already existsMsgBox "I think " & NewName & " already exists. Check the starting number"End Sub
Your minus sign is not really a minus sign. Overkey and the error goes away
Robert Berke
cut and paste it into word, highlight it then use alt x to see its unicode value.
a normal minus is \u002d but your minus is \u2013.
Instead of pasting t word,, you can paste the character into the top box at is https://www.branah.com/unicode-converter. That is a nice website for converting unicode text to unicode \u notation and the decimal equivalent.
By the way \u2013 is an En dash which is used to signify a range. for instance januayr endash december. Or atlantic endash pacific
Open in new window