Round several cells

Guentjo

Active Member
Joined
Jul 27, 2004
Messages
351
Office Version
  1. 2021
Platform
  1. Windows
I have put together a sheet that references several other tabs. The problem is, I should have round each cell to the 1000s (-3). I can't simply change one cell and copy/paste. Is there a way to add the round function to the beginning of every cell in a range?

I could replace "=" with "=round(", but how can I get the ",-3)" on the back w/o errors?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi Guentjo:

If you are open to a VBA solution, try the following ...
Code:
Sub AddFormulaToExistingRangeofEntries2()
    '=ROUND(existingEntry,3)
    'assuming the range is c2:c8
    Set yRange = [c2:c8]
    For Each cl In yRange
        cl.Value = "=round(" & Mid(cl.Formula, 2, Len(cl) - 1) & ",3)"
    Next cl
End Sub

Edited code per discussion with OP
 
Upvote 0
I'm open to VBA and I like that very much.

How could I change this so that it only effects the activecell?

Thanks.
 
Upvote 0
Guentjo said:
I'm open to VBA and I like that very much.
How could I change this so that it only effects the activecell?
Thanks.
Hi Guentjo:

Here we go ...
Code:
Sub AddFormulaToActiveCell()
    '=ROUND(existingEntry,3)
    ActiveCell = "=round(" & Mid(ActiveCell.Formula, 2, Len(ActiveCell) - 1) & ",3)"
End Sub
 
Upvote 0
And if you want to use it for a range of cells, then use the following instead ...
Code:
Sub AddFormulaToExistingRangeofEntries2()
    '=ROUND(existingEntry,3)
    'assuming the range is c2:c8
    Set yRange = [c2:c8]
    For Each cl In yRange
        cl.Value = "=round(" & Mid(cl.Formula, 2, Len(cl) - 1) & ",3)"
    Next cl
End Sub
 
Upvote 0
Great job. I modified it slightly to accomodate longer formula strings.

Code:
Sub AddFormulaToActiveCell()
    '=ROUND(existingEntry,-3)
    ActiveCell = "=round(" & Mid(ActiveCell.Formula, 2, Len(ActiveCell.Formula) - 1) & ",-3)"
End Sub

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,533
Members
448,969
Latest member
mirek8991

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