VBA: result with only one decimal

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

I need to display the result in cell (17, lc + 1) with only one decimal, but the following instructions don't work (the value remains with 9 decimals).

Code:
        Sheet1.Cells(17, lc + 1) = cell.Offset(0, 12).Value / cell.Offset(0, 8).Value
        Sheet1.Cells(17, lc + 1).NumberFormat = "0.0"

What is the correct instruction?

Thank's in advance.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Does this work?

Code:
Sheet1.Cells(17, lc + 1)= Int(Sheet1.Cells(17, lc + 1)*10)/10

retaining your first line of code and replacing the second one
 
Last edited:
Upvote 0
That would round the result down. If you need to just round to conventional rounding rules then just use round:

Code:
Sheet1.Cells(17, lc + 1) = Round(cell.Offset(0, 12).Value / cell.Offset(0, 8).Value, 1)
 
Upvote 0
That would round the result down. If you need to just round to conventional rounding rules then just use round:

Code:
Sheet1.Cells(17, lc + 1) = Round(cell.Offset(0, 12).Value / cell.Offset(0, 8).Value, 1)

Maybe I'm confused, but I'm not sure the two methods you have suggested store the real result.
I mean: if the result is 1.3854523 I'd like to display 1.4, but I need to use 1.3854523 for following operations.
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,400
Members
449,156
Latest member
LSchleppi

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