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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,215,338
Messages
6,124,343
Members
449,155
Latest member
ravioli44

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