![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Mar 2002
Posts: 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 |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
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.
__________________
Kind regards, Al Chara |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Mar 2002
Posts: 85
|
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 |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Mar 2002
Posts: 85
|
Anyone This Should Be Easy
|
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
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.
__________________
Kind regards, Al Chara |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Mar 2002
Posts: 85
|
Hi It Does Help One More Question How Do I Indent It?
|
|
|
|
|
|
#7 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Hit the tab button
|
|
|
|
|
|
#8 |
|
Board Regular
Join Date: Mar 2002
Posts: 85
|
Sorry I Suck At VB
|
|
|
|
|
|
#9 |
|
Board Regular
Join Date: Mar 2002
Posts: 85
|
Last Problem But Even When I Type In A Number It Still Says Please Enter A Valid Number
|
|
|
|
|
|
#10 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|