Help with FormulaR1C1 with IF using absolute comparison columns and rows

New2Dev

New Member
Joined
Sep 29, 2011
Messages
2
This is my first time posting in any forum but this problem has me stumped. Any help would be appreciated.

I have a worksheet with dates along the top row and dates along the right column, I need to place a "1" in the intersecting cells where the dates match. I am attempting to use the below code, but cannot get the absolute values for the top row in the formula of each cell.

(Dates are in Column A and need to be compared across dates in row 1)

Private Sub CommandButton1_Click()
Dim c As Range, r As Range
Dim num As String
num = "1"
Set c = Sheets("Sheet7").Range("B2:G12")
For Each r In c
r.FormulaR1C1 = "=IF(RC1=R[-1]C[0], " & """1""" & ", " & """""" & " )"
Next r
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi, welcome to the board!

That's a lot of code for that.

Does this do what you want?

Code:
Private Sub CommandButton1_Click()
Sheets("Sheet7").Range("B2:G12").Formula = "=IF($A2=B$1,1,"""")"
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,445
Members
452,915
Latest member
hannnahheileen

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