Adding a value and formula to same cell

craigg3

Board Regular
Joined
Dec 23, 2002
Messages
161
Office Version
  1. 2013
Platform
  1. Windows
Starting with cell "I9", that cell has a formula in it. I need a macro that will remove the formula from that cell, but leave the value while also adding a formula that will add cell "H9" to the value.
So, for example, if the formula in cell "I9" = 100, then I need the formula to be removed but keeping the value of 100 while also adding a formula that adds the value in cell "H9". So if cell "H9" has a value of 50, then the final value/formula in cell "I9" would be =100+H9....which would be 150 but do need the formula to link back to H9.

This would need to be done on the "I" column where the same row in column "F" <>""

There should only be about 40 or 50 rows that will need this code, but that may change at some point.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try this code:
VBA Code:
Sub AddFormulas()
    
    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Find last row in column I with data
    lr = Cells(Rows.Count, "I").End(xlUp).Row
    
'   Loop through all rows, starting with row 2
    For r = 2 To lr
'       See if column F is not blank
        If Cells(r, "F") <> "" Then
            Cells(r, "I").FormulaR1C1 = "=" & Cells(r, "I").Value & "+RC[-1]"
        End If
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution
Try this code:
VBA Code:
Sub AddFormulas()
   
    Dim lr As Long
    Dim r As Long
   
    Application.ScreenUpdating = False
   
'   Find last row in column I with data
    lr = Cells(Rows.Count, "I").End(xlUp).Row
   
'   Loop through all rows, starting with row 2
    For r = 2 To lr
'       See if column F is not blank
        If Cells(r, "F") <> "" Then
            Cells(r, "I").FormulaR1C1 = "=" & Cells(r, "I").Value & "+RC[-1]"
        End If
    Next r
   
    Application.ScreenUpdating = True
   
End Sub
Joe, works great. Thank you!
 
Upvote 0
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,957
Latest member
Hat4Life

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