rounding macro

1inus

New Member
Joined
Jul 6, 2006
Messages
40
I have several cells that sum (i.e. sum(d55:d64) or sum(aa1:aa15). is there a way to have a macro add the round formula to these cells so they will show:

round(sum(a1:a15)/1000,-.5)

thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
If you just put an "=" in front of your forumula, you should be ok.

I'm not sure why you need a macro to do this.

Also, I'm not sure you are using the Num_digits properly. I believe it should be an integer.

Code:
=ROUND(SUM(a1:a15)/1000,-5)
 
Upvote 0
What don't you use the copy command, copying the rounded formula to other applicable cells (you want rounded)?
 
Upvote 0
the equal sign is already there, the formulas currently will say

row A7=sum(a1:a5)
row A14=sum(a10:a12)
I actually should have written, =round(sum(a10:a12),0) to round to the nearest dollar.

I only was curious about a macro becasuse these formulas go in columns and vary in the amount of rows they sum,
=sum(a1:a5), =sum(b1:b5)
=sum(a10:a12), =sum(b10:b12)

so I can edit the formula in A7 and copy it accross the columns but I can not copy from A7 to A14 because A14 only sums 3 rows and not 5.

I was looking for a macro that would just add the round to the existing formula in cells that I have selected.

thanks
 
Upvote 0
Code:
Sub AddRound()

ActiveCell.Formula = "=ROUND(" & Mid(ActiveCell.Formula, 2) & ",0)"

End Sub

If you call that function while the cell is selected it will add your ROUND function.
 
Upvote 0
that works great but I try to divide the original sum by 1000

from = sum(a1:a10)
to =round(sum(a1:a10)/1000,0)

I keep putting that 1000 in a wrong spot in the macro.

Also, is there a way to do that to a range of cell I select? (from left to right, columns a1:c1)

thanks
 
Upvote 0
figured out my problem with the divide by thousand, just need help on doing this to every cell selected.

thanks
 
Upvote 0
Select all the cells that you want to update. Then run the following macro:
Code:
Sub AddRound()

For Each cell In Selection
    cell.Formula = "=ROUND(" & Mid(cell.Formula, 2) & ",0)"
Next cell

End Sub

-Tim
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,054
Latest member
juliecooper255

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