Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

z = x + y – 1

Posted on 2016-08-06
6
Medium Priority
?
107 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
[X]
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
  • 3
  • 2
6 Comments
 
LVL 22

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 22

Accepted Solution

by:
Roy Cox earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 22

Expert Comment

by:Roy Cox
ID: 41745602
Pleased to help
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

661 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