preventing rounding of decimals

dss28

Board Regular
Joined
Sep 3, 2020
Messages
165
Office Version
  1. 2007
Platform
  1. Windows
I have a userform and 2 sheets - sheet2 and sheet6.

While entering a quantity in number through userform, data stored on sheet 2 is same as entered. Simultaneously the data is then copied to sheet 6 as current stock. However the sheet 6 shows rounded off number eg. if my input value is 1.75 it round up to 2 or if it is 0.25 it shown as 0 on the sheet 6.

in both sheets, the column is formatted as number with 4 decimal places. even then it is rounded off.

request help in resolving.


VBA Code:
Private Sub CommandButton1_Click()
Dim I As Integer
Dim j As Integer
Dim final As Integer
Dim actual As Integer

For I = 1 To 1000
If Sheet2.Cells(I, 1) = "" Then
final = I
Exit For
End If
Next

Sheet2.Cells(final, 1) = UserForm2.ComboBox1
Sheet2.Cells(final, 2) = UserForm2.TextBox1
Sheet2.Cells(final, 3) = UserForm2.TextBox2
Sheet2.Cells(final, 4) = UserForm2.TextBox4
Sheet2.Cells(final, 5) = UserForm2.TextBox6
Sheet2.Cells(final, 6) = UserForm2.TextBox7
Sheet2.Cells(final, 7) = UserForm2.TextBox9     
Sheet2.Cells(final, 8) = UserForm2.TextBox10       
Sheet2.Cells(final, 9) = UserForm2.TextBox11         
Sheet2.Cells(final, 10) = UserForm2.TextBox12       
 

For j = 1 To 1000
If sheet6.Cells(j, 1) = Sheet2.Cells(final, 1) Then
actual = sheet6.Cells(j, 3)
final = UserForm2.TextBox2 + actual
sheet6.Cells(j, 3) = final
Exit For
End If
Next

UserForm2.ComboBox1 = ""
UserForm2.TextBox1 = ""
UserForm2.TextBox2 = ""
UserForm2.TextBox4 = ""
UserForm2.TextBox6 = ""
UserForm2.TextBox7 = ""
UserForm2.TextBox8 = ""
UserForm2.TextBox9 = ""
UserForm2.TextBox10 = ""
UserForm2.TextBox11 = ""
UserForm2.TextBox12 = ""


End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
if you want to show Decimal you should Declare Variables as Double Not Integer or Long
Then You should Use
VBA Code:
Dim Actual as Double
Dim final as Double
 
Upvote 0
Solution
thanks sir - done
but now the other userform - textbox9 where it is linked (see my earlier post of yday - multiple row data transfer from user form to same worksheet) is now showing round off which was not the case earlier.
will it be possible to review that code too. (tried to paste the post heading above if it can accessed through it)
 
Upvote 0
Then you can Use round formula to textbox value doesn't show decimals.
 
Upvote 0
thanks -- done, changed the declaration from integer to double in the other userforms which resolved the issue of rounding off....
thanks
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,139
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top