R1C1 Row to Absolute

gtd526

Well-known Member
Joined
Jul 30, 2013
Messages
696
Office Version
  1. 2019
Platform
  1. Windows
Hello,

I'm inserting the following formula via VBA. Once inserted, I fill the cells down with the same formula.

VBA Code:
  Range("I9").Select
    ActiveCell.FormulaR1C1 = _
    "=IFERROR(LOOKUP(2, 1/((COUNTIF(R[-1]C8:R[-1]C8, '[NBA.xlsm]Favs'!R4C9:R33C9)=0)*('[NBA.xlsm]Favs'!R4C9:R33C9<>"""")), '[NBA.xlsm]Favs'!R4C9:R33C9),"""")"

I use the [-1] to go back 1 row. The formula works perfectly, but I need to change it from Relative Row to Absolute Row, as stated below. Otherwise I have to change it manually, then fill down.

Once inserted the formula becomes:
IFERROR(LOOKUP(2, 1/((COUNTIF($H8:$H8, Favs!$I$4:$I$33)=0)*(Favs!$I$4:$I$33<>"")), Favs!$I$4:$I$33),"")

I want to change the $H8:$H8 to $H$8:$H8 when the formula is inserted.
What adjustments are needed to make the Row Absolute? Its only the 1st Row listed not both.

Thank you.
 
OK, things are much clearer now, and thank you for providing your actual data layout. If you're going to use the 'active cell' as the starting point for entering your formula, then you could use a variable in your code - for example:

VBA Code:
Dim i as Long
i = ActiveCell.Row - 1
ActiveCell.FormulaR1C1 = "=sum(R" & i & "C8:R[-1]C8)"

which gives you the following formula in cell I9 (if that was the active cell)
Excel Formula:
=SUM($H$8:$H8)
thank you.
It works with 'sum', but I have to use 'countif' so it's only listed once.
Im filling down 5 rows with this formula.
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Using the sample of data you provided in post #8, could you write a simple Countif formula - as you would want it to appear in cell H301 that you would then 'drag down' to cells H302:H306.
 
Upvote 0
Using the sample of data you provided in post #8, could you write a simple Countif formula - as you would want it to appear in cell H301 that you would then 'drag down' to cells H302:H306.
Here is the formula:

ActiveCell.FormulaR1C1 = _
"=IFERROR(LOOKUP(2, 1/((COUNTIF(R[-1]C8:R[-1]C8, '[NBA.xlsm]Favs'!R4C9:R33C9)=0)*('[NBA.xlsm]Favs'!R4C9:R33C9<>"""")), '[NBA.xlsm]Favs'!R4C9:R33C9),"""")"
 
Upvote 0
If your formula worked perfectly before:
The formula works perfectly
then add the following before your formula line:
VBA Code:
Dim i as Long
i = ActiveCell.Row - 1

and change your existing formula to:
Rich (BB code):
ActiveCell.FormulaR1C1 = _
    "=IFERROR(LOOKUP(2, 1/((COUNTIF(R" & i & "C8:R[-1]C8), '[NBA.xlsm]Favs'!R4C9:R33C9)=0)*('[NBA.xlsm]Favs'!R4C9:R33C9<>"""")), '[NBA.xlsm]Favs'!R4C9:R33C9),"""")"
 
Upvote 0
If your formula worked perfectly before:

then add the following before your formula line:
VBA Code:
Dim i as Long
i = ActiveCell.Row - 1

and change your existing formula to:
Rich (BB code):
ActiveCell.FormulaR1C1 = _
    "=IFERROR(LOOKUP(2, 1/((COUNTIF(R" & i & "C8:R[-1]C8), '[NBA.xlsm]Favs'!R4C9:R33C9)=0)*('[NBA.xlsm]Favs'!R4C9:R33C9<>"""")), '[NBA.xlsm]Favs'!R4C9:R33C9),"""")"
I entered your formula, but received an error: Application defined or object-defined error

VBA Code:
Dim i As Long

Range("H284").Select
i = ActiveCell.Row - 1

    ActiveCell.FormulaR1C1 = _
    "=IFERROR(LOOKUP(2, 1/((COUNTIF(R" & i & "C8:R[-1]C8), '[NBA.xlsm]Favs'!R4C9:R33C9)=0)*('[NBA.xlsm]Favs'!R4C9:R33C9<>"""")), '[NBA.xlsm]Favs'!R4C9:R33C9),"""")"
 
Upvote 0
There shouldn't be a closing bracket after the C8
 
Upvote 0
If your formula worked perfectly before:

then add the following before your formula line:
VBA Code:
Dim i as Long
i = ActiveCell.Row - 1

and change your existing formula to:
Rich (BB code):
ActiveCell.FormulaR1C1 = _
    "=IFERROR(LOOKUP(2, 1/((COUNTIF(R" & i & "C8:R[-1]C8), '[NBA.xlsm]Favs'!R4C9:R33C9)=0)*('[NBA.xlsm]Favs'!R4C9:R33C9<>"""")), '[NBA.xlsm]Favs'!R4C9:R33C9),"""")"
Thank you for the formula
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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