I am stuck in VBA. I have tried other solutions on the website but still can't get it right. I am using multiple modules and forms to get some information input into cells of Excel. But, when the msgBox is left blank it gives me a type 13 mismatch error. I have tried isNull but don't fully understand how to use it.
Any help would be much appreciated, and please keep any answers as simple as possible as I am a novice programmer at best. Thanks
Sub GetEndCostGateFees()
Dim qtyGateFees As Double
Dim msg As String
Const MinCost As Integer = 0
Const MaxCost As Integer = 200
msg = "Please enter the cost, per tonne, of Gate fees "
Do
qtyGateFees = InputBox(msg, "Gate Fees")
If IsNull(qtyGateFees) Then
MsgBox ("Please enter a value. Enter 0 if none")
End If
If IsNumeric(qtyGateFees) Then
If qtyGateFess >= MinCost And qtyGateFees <= MaxCost Then Exit Do
End If
msg = "Please enter a valid number"
msg = msg & vbNewLine
msg = msg & "Please enter number between " & MinCost & " and " & MaxCost
Loop
Sheet25.Range("B43").Value = qtyGateFees
End Sub
If you want the user to enter only Numeric Input then use Application.InputBox with Type:=1
Sub sample()
Dim Ret As Variant
Dim msg
msg = "Please enter the cost, per tonne, of Gate fees "
Ret = Application.InputBox(msg, "Gatefees", Type:=1)
If Ret <> False Then
'
'~~> Rest of your code here
'
End If
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With