Replace string with condensed version?

posty

New Member
Joined
Oct 17, 2006
Messages
23
I have this spreadsheet that has many entries in a cell similar to this:

=503+86+103+76+96+117+67+96+103+56+100+127+81+104

What I would like would be a macro (or something) that would go through any range that I request (say B5:b19) and replace each string like the above and replace it with the sum total. So it would yield in this cell...

=1715

There is a total of 9 columns that I would like to this to and many many columns, but there is data in between some of the rows that I would not want to touch.

Is this possible?

TIA
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Do you want exactly =1715 in the cell or just the value 1715?
 
Upvote 0
Do you want exactly =1715 in the cell or just the value 1715?

I would want the "=1715" so if and when things are added in the future, the addition would still occur. I just want to shrink the very large string to something manageable...
 
Upvote 0
Select the cells and try:

Code:
Sub Test()
    Dim Cell As Range
    On Error Resume Next
    For Each Cell In Selection.SpecialCells(xlCellTypeFormulas)
        Cell.Formula = "=" & Cell.Value
    Next Cell
End Sub
 
Upvote 0
Select the cells and try:

Code:
Sub Test()
    Dim Cell As Range
    On Error Resume Next
    For Each Cell In Selection.SpecialCells(xlCellTypeFormulas)
        Cell.Formula = "=" & Cell.Value
    Next Cell
End Sub

Perfect! Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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