VBA to insert a formula that uses A1 style fixed column variable row

sshone1

New Member
Joined
Jun 14, 2013
Messages
10
Hello, I need some help.

I am looking to have a macro write a formula into a cell using the A1 style. I need to be able write it as $D + Y, where Y is a variable number I have. I can't get the syntax correct. Please see below...

This one works perfectly...
copyWs.Range("B" & Y).Formula = "=IF(" & cName & "!B5=0,""""," & cName & "!B5)"

Now I want to do the same thing but this time I want to multiply B5 at the end of the if by a $D + Y. How do I merge the $D and the Y to become $D4, where y = 4?
copyWs.Range("U" & Y).Formula = "=IF(" & cName & "!B5=0,""""," & cName & "!B5*(""$D"" & Y &)"

Any help would be great.
Thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try this:
VBA Code:
copyWs.Range("U" & Y).Formula = "=IF(" & cName & "!B5=0,""""," & cName & "!B5*$D" & Y & ")"
 
Upvote 0
Thank you very much this worked perfect. I could of sworn that I tried this but I must of missed something. Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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