-
Solved: Display result to 3DP?
Hi
I'm developing some compensation calculators and have the following code in a userform.
[VBA]Sub CALCULATE()
Dim X As Integer
X = (TextBox1.Value / TextBox2.Value) - (TextBox1.Value / TextBox3.Value)
If X <= 1 Then
MsgBox ("Disadvantaged by " & X & " shares")
Else
MsgBox ("Advantaged by " & X & " shares")
End If
End Sub[/VBA]
I'd like the message box to display the value of X to 3 DP.
Any help appreciated
thanks
-
blackie42,
Here is code that should work for you. Notice that you need to change the type of your variable X so you will get decimal values since integers have 0 decimal places.[vba]Sub CALCULATE()
Dim X As Double
If X <= 1 Then
MsgBox ("Disadvantaged by " & Format(X, "0.###") & " shares")
Else
MsgBox ("Advantaged by " & Format(X, "0.###") & " shares")
End If
End Sub
[/vba]
HTH,
-
Thanks Ron - works well
Learn a little more each day from this great forum
regards
Jon
-
G'day, Jon,
Glad to help.!
Cheers,
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules