VB question...

stiffrimpet

New Member
Joined
Apr 10, 2002
Messages
10
I'm not sure if this is possible but I'll ask anyhoo.

I have this code:
---
Private Sub CalcButton_Click()

If CostBox.Value = "?" Then
MsgBox ("Invalid Cost")
CostBox.Value = ""
Else

If CostBox.Value = "?" Then
a = CostBox.Value
b = QuantityBox.Value
answer = a * b
SubCostBox.Text = answer
End If
End If
End Sub
---
The question marks are the problem. I need CostBox.Value to be any number but NOT a letter. Are there any wildcards I could use, one for letters and one for numbers?

Any help or put-downs at my gross incompetence would be much appreciated!

stiffrimpet
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try using the val function

if val(CostBox.Value) = 0 then
msgbox "you must enter numbers only
CostBox.Value = 0
endif
 
Upvote 0
Hi
Another function as well...

If Not IsNumeric(CostBox.Text) Then
Msgbox "You must enter numbers only."
CostBox.Text = ""
CostBox.SetFocus
End If

Tom
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,267
Members
448,558
Latest member
aivin

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