How to write the code for return value of textbox divided by another Textbox
- zjy007ai007
- Thread is marked as Resolved.
-
-
Welcome to Ozgrid Forum. An example workbook is much better than an image..
An entry in a TextBox is by default a String so you cannot use them in calculations even if they look like a number. You need to convert the String to a Numeric value as you have using Val(TextBox4.value). All TextBoxes for the calculation must be changed you can use Val, cInt, cDbl. For a list of conversion functions see:-
-
Hello
Take a look to the following lines:
If you want to add more restrictions use the Url
Option Explicit
Sub f_l()
Dim fs As Double
With Sheet1
If (Not VarType(.TextBox1.Value) = vbString And Not .TextBox1.Value = 0) And _
(Not VarType(.TextBox2.Value) = vbString And Not .TextBox1.Value = 0) Then
fs = .TextBox1.Value / .TextBox2.Value
End If
End With
End Sub
''' https://docs.microsoft.com/en-…ace-help/vartype-function
Regards
DP
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!