VB Code Needed or Data Forms

Morrissey

Board Regular
Joined
Mar 8, 2002
Messages
85
Hi,

I've Made A Data Form Using Visual Basic And I've made An Input Where You Type Something And It Goes To The Requested Cell, However I Would Like It To Be Data That Is Valid So When Someone Types In The (For Example) Invoice Number 'S' A Pop Up Menu Will Say Please Enter A Number So I'd Like The Data Input Into The Box Only Data If It Helps Here IS The Code I've Started With:

Private Sub cmdEnterInvoiceData_Click()
Sheet1.Range("b11").Value = txtInvoiceNum

End Sub

Private Sub UserForm_Click()

End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try the following code:

If Application.WorksheetFunction.IsNumber(txtInvoiceNum) = False Then MsgBox "Enter in a valid number"
Else: Sheet1.Range("b11").Value = txtInvoiceNum
End If

The code tests whether or not txtInvoiceNum is a number or not.
 
Upvote 0
Al Chara Thank You Very Much For Your Help However There Is A Problem (For Help Here Is The Code)

Private Sub cmdEnterInvoiceData_Click()
If Application.WorksheetFunction.IsNumber(txtInvoiceNum) = False Then MsgBox "Enter in a valid number"
Else: Sheet1.Range("b11").Value = txtInvoiceNum
End If


End Sub

Private Sub UserForm_Click()

End Sub


When I click something it says I have to debug it and in THe VB editor When I Scroll Through It Displays This Error Message:

Compile Error:

Else Without If

Can You Give Me A Bit More Guidance Muchos Gracias
 
Upvote 0
Try the following code:

If Application.WorksheetFunction.IsNumber(txtInvoiceNum) = False Then
MsgBox "Enter in a valid number"
Else: Sheet1.Range("b11").Value = txtInvoiceNum
End If

To be careful make sure [MsgBox "Enter in a valid number"] is indented.
 
Upvote 0
Try the following: -

Private Sub cmdEnterInvoiceData_Click()

On Error GoTo WrongInput
Sheet1.Range("b11").Value = CDbl(txtInvoiceNum.Text)
Exit Sub

WrongInput:
MsgBox "Please enter a number"
txtInvoiceNum.Text = ""
txtInvoiceNum.SetFocus

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,085
Members
448,548
Latest member
harryls

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