Easiest way to update formula

Sufiyan97

Well-known Member
Joined
Apr 12, 2019
Messages
1,538
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
is there any easiest way to update below formula as per expected?

Book3
AB
1RawExpected
2='PL Trend'!C10=SUM('PL Trend'!C10:D10)
3='PL Trend'!C11=SUM('PL Trend'!C11:D11)
4='PL Trend'!C23=SUM('PL Trend'!C23:D23)
5='PL Trend'!C33=SUM('PL Trend'!C33:D33)
6
7
Sheet1
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Here is one way:
VBA Code:
Sub MyReplaceFormulaMacro()

    Dim lr As Long
    Dim r As Long
    Dim frm As String
    Dim rw As Long
    Dim frm2 As String

    Application.ScreenUpdating = False

'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Loop through all rows starting with row 2
    For r = 2 To lr
'       Get current formula
        frm = Range("A" & r).Formula
'       Get row from current formula
        rw = Mid(frm, InStr(frm, "!C") + 2)
'       Create new formula
        frm2 = "=SUM(" & Mid(frm, 2) & ":D" & rw & ")"
'       Populate column B with new formula
        Range("B" & r).Formula = frm2
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 1
Solution
Thank you very much Joe,

It works as expected.
 
Upvote 0
You are welcome.
 
Upvote 0

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

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