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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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,214,611
Messages
6,120,509
Members
448,967
Latest member
screechyboy79

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