FormulaR1C1, cell not referring to itself error

gtd526

Well-known Member
Joined
Jul 30, 2013
Messages
657
Office Version
  1. 2019
Platform
  1. Windows
Hello,
The following code works, but when I Offset from another cell to the correct cell and enter the formula, I receive an error (row 48 only being entered). Thank you.
Here is the formula:
Wagers.xlsm
A
47With Range("H" & Rows.Count).End(xlUp)
48 .FormulaR1C1 = "=IFERROR(LOOKUP(2, 1/((COUNTIF(R" & .Row - 1 & "C8:R[-1]C8,'[NFL.xlsm]Weekly Picks'!R4C8:R35C8)=0)*('[NFL.xlsm]Weekly Picks'!R4C8:R35C8<>"""")),'[NFL.xlsm]Weekly Picks'!R4C8:R35C8),"""")"
49End With
NFL to R1C1
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Can you post the actual code in code tags, rather than a mini sheet.
Also what is the error you get?
 
Upvote 0
Can you post the actual code in code tags, rather than a mini sheet.
Also what is the error you get?
Here is the code:
VBA Code:
Sub Test4()
'(2)
'Offset to cell and enter formula for Reg Bets and Parlay Bets
'each formula refers to a "list", has to be 1 cell up from range, not to refer to itself, otherwise teams will flip positions
'this way it stays consistant

'enters the formula for Regular My Betting Team, list of
    LastRow = Cells(Rows.Count, "B").End(xlUp).Row      'last row according to "B"
    Range("E" & LastRow).Select  'have to SELECT lastRow to select correct range regarding line below
    Selection.Offset(0, 3).Select
    'insert formula HERE
    'below formula .Row error when by itself, need formula without .Row
    
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'enters the formula for my Parlay Team, list of
'need to use IFNA to enter 0, 0 doesn't effect Parlay W/L formula, #N/A does (if error, doesn't work)

    LastRow = Cells(Rows.Count, "B").End(xlUp).Row      'last row according to "B"
    Range("E" & LastRow).Select  'have to SELECT lastRow to select correct range regarding line below
    Selection.Offset(2, 3).Select
    'insert formula HERE
'    With Range("H" & Rows.Count).End(xlUp)
        ActiveCell.FormulaR1C1 = "=IFNA(LOOKUP(2, 1/((COUNTIF(R" & .Row - 1 & "C8:R[-1]C8,'[NFL.xlsm]Weekly Picks'!R4C8:R35C8)=0)*('[NFL.xlsm]Weekly Picks'!R4C8:R35C8<>"""")*('[NFL.xlsm]Weekly Picks'!$F$4:$F$35=" * ")),'[NFL.xlsm]Weekly Picks'!R4C8:R35C8),0)"
'    End With


End Sub

Here is the error I'm receiving:
Capture2.PNG
 
Upvote 0
As Mike mentioned, you're essentially doing COUNTIF(R[-1]C8:R[-1]C8 which is only one cell, so there's no need to repeat the reference.
 
Upvote 0
You are getting that error, because you have removed the With statement.
Try what mikerickson suggested.
 
Upvote 0
With the latest code, you need to remove the quotes.
 
Upvote 0
Try
VBA Code:
ActiveCell.FormulaR1C1 = "=IFNA(LOOKUP(2, 1/((COUNTIF(R[-1]C8,'[NFL.xlsm]Weekly Picks'!R4C8:R35C8)=0)*('[NFL.xlsm]Weekly Picks'!R4C8:R35C8<>"""")*('[NFL.xlsm]Weekly Picks'!r4c6:r35c6="" * "")),'[NFL.xlsm]Weekly Picks'!R4C8:R35C8),0)"
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,684
Members
449,116
Latest member
HypnoFant

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