Rounding and Decimal Place Issue

bb29829

Registered User.
Local time
Today, 17:15
Joined
Dec 4, 2014
Messages
17
I am importing values from an excel spreadsheet after running regression analysis. I bring the numbers over using the code below. However, the numbers come in and automatically round to the nearest whole number. I need them out to the second decimal point. I have tried using "general number" and "fixed", both with 2 decimal places. General number doesn't do anything and fixed just puts in x.00. Can anyone help with this issue?

Thanks again!

Private Sub Command279_Click()
Dim xl As Object
Dim xlWrkBk As Object
Dim xlSht As Object
Set xl = CreateObject("Excel.Application")
xl.Visible = True
Set xlWrkBk = xl.Workbooks.Open("I:\My Offers\" & Job_Code & "_Regression.xls")
Set xlSht = xlWrkBk.Worksheets(1)
[C1] = xlSht.cells(18, 2)
[C2] = xlSht.cells(19, 2)
[C3] = xlSht.cells(20, 2)
[C4] = xlSht.cells(21, 2)
[Y-Intercept] = xlSht.cells(17, 2)
[Multiple_R] = xlSht.cells(4, 2)
[R_Squared] = xlSht.cells(5, 2)
[F_Value] = xlSht.cells(12, 5)
[Sig_F] = xlSht.cells(12, 6)
[Observations] = xlSht.cells(8, 2)

xlWrkBk.Close False
xl.Quit 'Close Excel
Set xlSht = Nothing
Set xlWrkBk = Nothing
Set xl = Nothing
End Sub
 
First off, please use the CODE tags and proper indentation to make your code more legible - it helps immensely.

Second, my initial guess would be to check the data types in the table you're updating. You wouldn't be the first person to accidentally try to import data with decimal points into an integer field. Check the fields, too, as well as their format properties.
 
Do you need to declare the vars?



??

It's a command button, so those are field references, not variables. They don't actually show until he saves and refreshes the form, but that approach technically works.

Personally I change the text boxes directly, as changes are visible to the user immediately, but I figured one issue at a time. :D
 
Don't guess Ive ever done that before -
 
I wouldn't call it good practice, seeing as it doesn't actually show the changes until you save and refresh, but it does work.
 

Users who are viewing this thread

Back
Top Bottom