vba rounding

Matt111

Board Regular
Joined
Jul 20, 2004
Messages
83
Hi, tried searching on topic but didnt come across anything conclusive. I'm trying to get a 'normal' rounding function using vba by that i mean 2.466 = 2.47 or 2.562 = 2.56 etc (as opposed to something i've read about called Bankers rounding). So i have the following but in effect it returns 0dp, and tbh i dont think Roundup is what i'm looking for either...! can anyone help please? Matt.

Code:
' Convert numbers in selection to 2dp
Dim c As range
Dim i As Integer
For Each c In Selection.Cells
i = WorksheetFunction.RoundUp(c.Value, 2)
c.Value = i
Next
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try

Rich (BB code):
Dim c As Range
Dim d As Double
For Each c In Selection.Cells
    d = WorksheetFunction.Round(c.Value, 2)
    c.Value = i
Next
 
Upvote 0
Hi thats great thank you very much, the last bit is c.value = d i assume of course. Many thanks.
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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