How to convert VBA IF formula into R1C1 format

MixedUpExcel

Board Regular
Joined
Apr 7, 2015
Messages
222
Office Version
  1. 365
Platform
  1. Windows
Hi,

Quick question as I just can't figure it out, please can someone show me how to convert the following into R1C1 format:

MyColumn in this case is where I have a cell selected - in this case I have selected a cell somewhere in Column A but in the future, I might select Column F or Z etc etc.

Code:
With Range(Cells(2, MyColumn + 1), Cells(lr, MyColumn + 1))
  .Formula = [B][COLOR=#b22222]"=IF(A2<>"""",""a"","""")"[/COLOR][/B]
  .Value = .Value
End With

Thanks.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Assuming you want to refer to the column to the left of the formula column:

Code:
.FormulaR1C1 = "=IF(RC[-1]<>"""",""a"","""")"

will do the job.
 
Upvote 0
A little trick you can use, especially if you want to see what a formula looks like in R1C1 format.
That is the format that the Macro Recorder uses, by default.
So, if you turn on the Macro Recorder, and record yourself manually entering the formula directly into your sheet, and stop the recorder, you can view the code and see what the formula needs to look like!
 
Upvote 0
I use the immediate window in the VB Editor and enter:

Code:
?Replace$(activecell.formular1c1, """", """""")

which outputs the correct R1C1 style formula with any quotes doubled up so it can be used directly in my code.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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