R1C1 code question

MOB

Well-known Member
Joined
Oct 18, 2005
Messages
1,055
Office Version
  1. 365
Platform
  1. Windows
I have a line of code as follows;

Code:
ActiveCell.Offset(0, 58).FormulaR1C1 = "=If(MONTH($C$2)&YEAR($C$2)=MONTH(RC[-49])&YEAR(RC[-49]),""Y"","")"

Which should return a formula like this;

=IF(MONTH($C$2)&YEAR($C$2)=MONTH($F7)&YEAR($F7),"Y","")

But when I run the code, it does nothing.

I think its something to do with the R1C1 bits, but I don't know how to correct it!

What am I doing wrong?

TIA
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Thanks Andrew

I've amended it to the code below, but when I run the code it still enters nothing in the cell, is there something else I'm doing wrong?

ActiveCell.Offset(0, 58).FormulaR1C1 = "=If(MONTH(R2C3)&YEAR(R2C3)=MONTH(RC[-49])&YEAR(RC[-49]),""Y"","")"
 
Upvote 0
ActiveCell.Offset(0, 58).FormulaR1C1 = "=If(MONTH(R2C3)&YEAR(R2C3)=MONTH(RC[-49])&YEAR(RC[-49]),""Y"","""")"

Adding two " near the end seems to fix it, weird :)
 
Upvote 0
You need to double up the last quotes:

Rich (BB code):
ActiveCell.Offset(0, 58).FormulaR1C1 = "=If(MONTH(R2C3)&YEAR(R2C3)=MONTH(RC[-49])&YEAR(RC[-49]),""Y"","""")"
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,897
Members
449,097
Latest member
dbomb1414

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