Converting Cells.Address to relative address in VBA for excel

m_graham_canada

New Member
Joined
Oct 11, 2007
Messages
6
Hi there,

I'm using VBA in excel and want to do the following as I would have done in a worksheet:
I have simplified my example tremendously, but I think this is adequate.

suppose cell A1 has the number 2
suppose the cell B1 has the number 3

in cell A2 in excel I would type "=sum(A1,B1)"

in vba I want to do the same, BUT I don't know the actual cell address and I want the ability to copy to other cells using relative addressing.
So far I am able to code:
variable_x="=" & Cells(ProductLineRow(1), r1USD).Address & "+" & Cells(ProductLineRow(1), r2USD).Address

(The range(cells) just hasn't been working for me. Not sure why.)

So my equation is great, except the result is not relative. It gives me back =$A$1+$B$1 in my cell. I want to see =A1+B1.
I tried doing .address.indirect but vba doesn't like that either. Not sure of correct syntax.

Any thoughts how to do this?

Thanks.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You can use:
Code:
Cells(ProductLineRow(1), r2USD).Address(0,0)
or if you use R1C1 style addressing to build the formula, it is easier to put the formula into multiple cells at once.
Regards,
Rory
 
Upvote 0

Forum statistics

Threads
1,215,634
Messages
6,125,931
Members
449,274
Latest member
mrcsbenson

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