Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number Formatting on a Userform Output

Status
Not open for further replies.

bstanton

Technical User
Jan 15, 2009
8
US
I am using a user form to display calculations made using data from a spreadsheet. The code I have written produces the intended result, except I am having trouble figuring out how to format the output to the correct number of decimal places. For example, I would like the value for CalcGmb to display to three decimal places e.g. "0.000", but instead it displays as "0.000000". So far, the standard method to format the cell number format like NumberFormat = "0.000" has not worked. Hopefully someone has some ideas on how to make this work. Thank you in advance for your assistance.

Sub test()
'
' Defines the variables
'
Dim JMFGmm As Single
Dim JMFGmb As Single
Dim JMFVa As Single
Dim JMFVMA As Single
Dim JMFVFB As Single
Dim JMFUW As Single
Dim CalcGmm As Single
Dim CalcGmb As Single
Dim CalcVa As Single
Dim CalcVMA As Single
Dim CalcVFB As Single
Dim CalcUW As Single
Dim CalcDPE As Single
'
' Defines the JMF Values on the userform
'
JMFGmm = Range("G55")
JMFGmb = JMFGmm * 0.96
JMFVa = Range("K55")
JMFVMA = Range("M55")
JMFVFB = Range("O55")
JMFUW = Range("Q55")
'
' Calculates the volumetrics based on the data in the spreadsheet
'
CalcGmm = 100 / (((100 - Range("D55")) / Range("I47")) + (Range("D55") / Range("U12")))
CalcGmb = CalcGmm * 0.96
CalcVa = ((CalcGmm - CalcGmb) / CalcGmm) * 100
CalcVMA = 100 - ((100 - Range("D55")) * CalcGmb) / Range("W43")
CalcVFB = ((CalcVMA - CalcVa) / CalcVMA) * 100
CalcUW = CalcGmb * 997.3
CalcDPE = Range("W41") / (Range("D55") - (((100 * Range("U12") * ((Range("I47") - Range("W43")) / _
(Range("I47") * Range("W43"))))) / 100) * (100 - Range("D55")))
'
' Displays the cell data and calculations on the userform
'
Mix_Properties.JMFGmm = JMFGmm
Mix_Properties.JMFGmb = JMFGmb
Mix_Properties.JMFVa = JMFVa
Mix_Properties.JMFVMA = JMFVMA
Mix_Properties.JMFVFB = JMFVFB
Mix_Properties.JMFUW = JMFUW
Mix_Properties.CalcGmm = CalcGmm
Mix_Properties.CalcGmb = CalcGmb
Mix_Properties.CalcVa = CalcVa
Mix_Properties.CalcVMA = CalcVMA
Mix_Properties.CalcVFB = CalcVFB
Mix_Properties.CalcUW = CalcUW
Mix_Properties.CalcDPE = CalcDPE
'
' Shows the userform the data
'
Mix_Properties.Show vbModeless
'
Application.ScreenUpdating = True
'
End Sub
 
What happens if you replace this:
Mix_Properties.CalcGmm = CalcGmm
with this ?
Mix_Properties.CalcGmm = Format(CalcGmm, "0.000")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi,

Just a thot--why not use the spreadsheet as a form? Is a form really necessary?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
PHV,

Your suggestion worked beatifully. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top