Add formula w/ dynamic column reference

boothrat

New Member
Joined
Feb 4, 2014
Messages
13
Sorry, this is a double hit. Looked like my previous post w/ the same question didn't post but I was mistaken

I'm rying to write a macro that adds to the end of the formula in a selected cell. I need the formula to updated to reflect the column that the cell is in. The cell won't always be in the same row but will always reference it's own column, even on the other sheet. (ie: column "N" in the example below needs to change to whatever column the cell is in)

Code:
Sub Date_Cbl_Add()

Dim Contents As String


    Contents = ActiveCell.Formula
    ActiveCell.Formula = Contents & "+((Totals!N$33+Totals!N$34+Totals!N$35)*Data!N$45*0.6)"




End Sub
 
Last edited:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Something like this:
Code:
Sub Date_Cbl_Add()
Dim Contents As String[COLOR=#ff0000], clm As String[/COLOR]
Contents = ActiveCell.Formula
[COLOR=#ff0000]clm = Split(ActiveCell.Address, "$")(1)[/COLOR]
ActiveCell.Formula = Contents & "+((Totals![COLOR=#ff0000]" & clm & "[/COLOR]$33+Totals![COLOR=#ff0000]" & clm & "[/COLOR]$34+Totals![COLOR=#ff0000]" & clm & "[/COLOR]$35)*Data![COLOR=#ff0000]" & clm & "[/COLOR]$45*0.6)"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,528
Messages
6,120,065
Members
448,942
Latest member
sharmarick

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