vba: How to make FormulaR1C1 dynamic

Xceller

Active Member
Joined
Aug 24, 2009
Messages
265
Thank you in advance for your help!

I want replace 3963 with Lr1 and 3752 with Lr2.

Sub ChkMatchNative()

Dim Lr1 As Long
Dim Lr2 As Long



Lr1 = Cells(Rows.Count, "A").End(xlUp).Row
Lr2 = Cells(Rows.Count, "F").End(xlUp).Row


Range("D3").Resize(Lr1, 1).FormulaR1C1 = "=IF(RC3=SUMPRODUCT((R3C7:R3963C7=RC2)*(R3C9:R3963C9=RC3),R3C9:R3963C9),""X"","""")"
Range("J3").Resize(Lr2, 1).FormulaR1C1 = "=IF(RC9=SUMPRODUCT((R3C2:R3752C2=RC7)*(R3C3:R3752C3=RC9),R3C3:R3752C3),""X"","""")"



End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi

Try:

Code:
Range("D3").Resize(Lr1, 1).FormulaR1C1 = "=IF(RC3=SUMPRODUCT((R3C7:R" & Lr1 & "C7=RC2)*(R3C9:R3963C9=RC3),R3C9:R[COLOR=#000000]" & Lr1 & "[/COLOR]C9),""X"","""")"
 
Upvote 0
Try:
Code:
Sub ChkMatchNative()

Dim Lr1 As Long, Lr2 As Long



Lr1 = Cells(Rows.Count, "A").End(xlUp).Row
Lr2 = Cells(Rows.Count, "F").End(xlUp).Row


Range("D3").Resize(Lr1, 1).FormulaR1C1 = "=IF(RC3=SUMPRODUCT((R3C7:R" & Lr1 & "C7=RC2)*(R3C9:R" & Lr1 & "C9=RC3),R3C9:R" & Lr1 & "C9),""X"","""")"
Range("J3").Resize(Lr2, 1).FormulaR1C1 = "=IF(RC9=SUMPRODUCT((R3C2:R" & Lr2 & "C2=RC7)*(R3C3:R" & Lr2 & "C3=RC9),R3C3:R" & Lr2 & "C3),""X"","""")"



End Sub

Hope it helps.
 
Upvote 0
Try:
Code:
Sub ChkMatchNative()

Dim Lr1 As Long, Lr2 As Long



Lr1 = Cells(Rows.Count, "A").End(xlUp).Row
Lr2 = Cells(Rows.Count, "F").End(xlUp).Row


Range("D3").Resize(Lr1, 1).FormulaR1C1 = "=IF(RC3=SUMPRODUCT((R3C7:R" & Lr1 & "C7=RC2)*(R3C9:R" & Lr1 & "C9=RC3),R3C9:R" & Lr1 & "C9),""X"","""")"
Range("J3").Resize(Lr2, 1).FormulaR1C1 = "=IF(RC9=SUMPRODUCT((R3C2:R" & Lr2 & "C2=RC7)*(R3C3:R" & Lr2 & "C3=RC9),R3C3:R" & Lr2 & "C3),""X"","""")"



End Sub

Hope it helps.


northwolves & pgc01

Thank you all for your help. It works great now.
 
Upvote 0

Forum statistics

Threads
1,203,067
Messages
6,053,334
Members
444,654
Latest member
Rich Cohen

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