using a hyphen on Userform.

rlink_23

Board Regular
Joined
Oct 30, 2015
Messages
149
In my Userform I have this code that when you put the customer number in and it populates the textBoxes with the customer info. I have a few customers that have a dash at the end such as 45610-2. It will not let me add a hyphen (dash). Is there a way I can use the dash on the userfom? Thank you kindly for your help!! :)

Code I speak about above

Code:
Private Sub custnumber_Change()Dim I As Long, Lastrow As Long
Lastrow = Sheets("Customers").Range("A" & Rows.Count).End(xlUp).Row
For I = 1 To Lastrow


If Sheets("Customers").Cells(I, "A").Value = custnumber Or _
Sheets("Customers").Cells(I, "A").Value = Val(custnumber) Then


Me.custnumber = Sheets("customers").Cells(I, "A").Value
Me.company = Sheets("Customers").Cells(I, "B").Value
Me.TextBox7 = Sheets("Customers").Cells(I, "C").Value
Me.Phone1 = Sheets("Customers").Cells(I, "E").Value


Me.ZipCode = Sheets("Customers").Cells(I, "D").Value
Me.Email = Sheets("Customers").Cells(I, "F").Value






End If
If custnumber = "" Then
Me.company = Clear
Me.TextBox7 = Clear
Me.Phone1 = Clear
Me.ZipCode = Clear
Me.Email = Clear


End If
Next




End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Is that all the code?

There's nothing in it that would prevent a hyphen being entered.:eek:
 
Upvote 0
In my Userform I have this code that when you put the customer number in and it populates the textBoxes with the customer info. I have a few customers that have a dash at the end such as 45610-2. It will not let me add a hyphen (dash). Is there a way I can use the dash on the userfom? Thank you kindly for your help!! :)

Code I speak about above

Code:
Private Sub custnumber_Change()Dim I As Long, Lastrow As Long
Lastrow = Sheets("Customers").Range("A" & Rows.Count).End(xlUp).Row
For I = 1 To Lastrow

If Sheets("Customers").Cells(I, "A").Value = custnumber Or _
Sheets("Customers").Cells(I, "A").Value = [B][COLOR="#FF0000"][SIZE=3]Val([/SIZE][/COLOR][/B]custnumber[B][COLOR="#FF0000"][SIZE=3])[/SIZE][/COLOR][/B] Then

Me.custnumber = Sheets("customers").Cells(I, "A").Value
Me.company = Sheets("Customers").Cells(I, "B").Value
Me.TextBox7 = Sheets("Customers").Cells(I, "C").Value
Me.Phone1 = Sheets("Customers").Cells(I, "E").Value

Me.ZipCode = Sheets("Customers").Cells(I, "D").Value
Me.Email = Sheets("Customers").Cells(I, "F").Value

End If
If custnumber = "" Then
Me.company = Clear
Me.TextBox7 = Clear
Me.Phone1 = Clear
Me.ZipCode = Clear
Me.Email = Clear

End If
Next

End Sub
Without setting up a test, I am pretty sure your problem stems from the use of the Val function (highlighted in red above)... it returns the number appearing before the first non-floating point character which, in this case, is the minus sign.
 
Upvote 0
except now the regular customer number won't work. Only with Hyphens. how do I proceed?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top