Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

z = x + y – 1

Posted on 2016-08-06
6
74 Views
Last Modified: 2016-08-06
Why do I have a Syntax Error for "z = x + y – 1"


Private Sub cmdAddSheets_Click()
'dim variables
Dim x As Integer
Dim y As Integer
Dim z As Integer
'set error handler
On Error GoTo Copier_Error
'turn off screen updating and calculation
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'check if the workbook isshared and exit if it is
If ThisWorkbook.MultiUserEditing Then
MsgBox "Please Unshare the workbook before you proceed"
Exit Sub
End If
'check that all values are in the userform
If Me.txtName = "" Or Me.cboNum = "" Or Me.cboNumSt = "" Then
MsgBox "You forgot to add the parematers for the sheet name."
Exit Sub
End If
'protect_all
Protect_All
'set variables for number of sheet
x = Me.cboNum.Value
'set variable for sheet name prefix
y = Me.cboNumSt.Value
z = x + y – 1
'check the first sheet name
NewName = Sheet1.Range("A4")
'loop through to check
For Each sh In ThisWorkbook.Worksheets
If sh.Name = NewName Then
MsgBox "This information already exists.You are not permitted to copy over it"
'if sheet name exists then got to end of sub
GoTo Copier_Error:
End If
Next
'run loop to add sheets
For numtimes = y To z
Sheet3.Copy after:=Worksheets(Worksheets.Count)
'create the new sheet name
ActiveSheet.Name = Me.txtName & numtimes
Next
'return to Interface sheet
Sheet1.Select
'list workshhet names on the interface
ListWorkSheetNames
'turn of screen updating and calculation
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
'error handler
On Error GoTo 0
Exit Sub
Copier_Error:
'message if sheet already exists
MsgBox "I think " & NewName & " already exists.  Check the starting number"
End Sub

Open in new window

0
Comment
Question by:AaronBanker
  • 3
  • 2
6 Comments
 
LVL 18

Expert Comment

by:Roy_Cox
ID: 41745494
Use Val to convert to numeric, by default your code in a userform is using Strings because TextBox value, ComboBoxe values etc default to Strings

'set variables for number of sheet
x = Val(Me.cboNum.Value)
'set variable for sheet name prefix
y = Val(Me.cboNum

Open in new window

0
 
LVL 18

Accepted Solution

by:
Roy_Cox earned 500 total points
ID: 41745502
Here's a tip, don't use error handlers until your code is fully tested because you are switching off helpful messages
0
 
LVL 5

Expert Comment

by:rberke
ID: 41745527
Your minus sign is not really a minus sign. Overkey and the error goes away
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Expert Comment

by:rberke
ID: 41745546
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
0
 

Author Closing Comment

by:AaronBanker
ID: 41745583
Thanks for the help
0
 
LVL 18

Expert Comment

by:Roy_Cox
ID: 41745602
Pleased to help
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question