preventing rounding of decimals

dss28

Board Regular
Joined
Sep 3, 2020
Messages
61
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
 

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
1,687
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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
 
Solution

dss28

Board Regular
Joined
Sep 3, 2020
Messages
61
Office Version
  1. 2007
Platform
  1. Windows
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)
 

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
1,687
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Then you can Use round formula to textbox value doesn't show decimals.
 

dss28

Board Regular
Joined
Sep 3, 2020
Messages
61
Office Version
  1. 2007
Platform
  1. Windows
thanks -- done, changed the declaration from integer to double in the other userforms which resolved the issue of rounding off....
thanks
 

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
1,687
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
You're Welcome & thanks for feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,128,158
Messages
5,629,032
Members
416,362
Latest member
Cocito

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
Top