In a worksheet function in Excel, how do you self-reference the cell, column or row you're in?
-
Dup of http://stackoverflow.com/questions/757413/excel-reference-to-current-cell that has more solutions in answers. – Vadzim Oct 16 '14 at 18:38
10 Answers
For a cell to self-reference itself:
INDIRECT(ADDRESS(ROW(), COLUMN()))
For a cell to self-reference its column:
INDIRECT(ADDRESS(1,COLUMN()) & ":" & ADDRESS(65536, COLUMN()))
For a cell to self-reference its row:
INDIRECT(ADDRESS(ROW(),1) & ":" & ADDRESS(ROW(),256))
or
INDIRECT("A" & ROW() & ":IV" & ROW())
The numbers are for 2003 and earlier, use column:XFD and row:1048576 for 2007+.
Note: The INDIRECT function is volatile and should only be used when needed.

- 22,383
- 32
- 112
- 130
-
I found your first code sample useful - using OFFSET(ADDRESS(ROW(),COLUMN()),0,-1) I was able to define a name whose formula referred to the cell left of that in which the name was used. Perhaps unnecessary given the way Excel handles dragging or copying formulas with absolute or relative references; but a neat way of defining a formula that relies on nearby cells. – Matt Nov 28 '12 at 06:46
-
1Awesome, the cell self-reference is great for conditional formatting! It needs to be localized however. To test for empty cell in German Excel, I need to use `=ISTLEER(INDIREKT(ADRESSE(ZEILE();SPALTE())))` – CodeManX Dec 12 '13 at 00:39
-
Wonderful solution! This way i can apply the same conditional formatting to a range of cells, using copy-paste, while referring the value of each cell indirectly to format it!! – Zecas Jun 29 '16 at 17:41
-
I love this. Very useful when you need a custom function in a worksheet to look at the cell that its in. – PBeezy Feb 07 '20 at 15:47
where F13 is the cell you need to reference:
=CELL("Row",F13) yields 13; its row number
=CELL("Col",F13) yields 6; its column number;
=SUBSTITUTE(ADDRESS(1,COLUMN(F13)*1,4),"1","") yields F; its column letter

- 98,240
- 88
- 296
- 433

- 116
- 1
- 2
I don't see the need for Indirect, especially for conditional formatting.
The simplest way to self-reference a cell, row or column is to refer to it normally, e.g., "=A1" in cell A1, and make the reference partly or completely relative. For example, in a conditional formatting formula for checking whether there's a value in the first column of various cells' rows, enter the following with A1 highlighted and copy as necessary. The conditional formatting will always refer to column A for the row of each cell:
= $A1 <> ""

- 27,214
- 6
- 67
- 115
-
1that's true for conditional formatting, but it gives you circular reference errors otherwise. – Lance Roberts Jun 13 '11 at 20:34
-
I just tested it in 2010, and it works good for full columns also. – Lance Roberts Jun 13 '11 at 20:38
-
1I was just editing my answer to reflect that, so we're on the same wave-length. CF was the only specific use you mentioned in your post. – Doug Glancy Jun 13 '11 at 20:38
-
1Yep, that seems to be the biggest use, but I've ran into the need in other places. – Lance Roberts Jun 13 '11 at 20:39
-
Well I just had a big need for this, and tried relative referencing and it didn't work, so I'm not sure when it will or won't. – Lance Roberts Jul 05 '11 at 22:19
-
With conditional formatting? If you want to give details maybe I can help. – Doug Glancy Jul 06 '11 at 20:10
-
I solved the problem, and the relative referencing worked in the end. Thanks. – Lance Roberts Jul 06 '11 at 21:39
There is a better way that is safer and will not slow down your application. How Excel is set up, a cell can have either a value or a formula; the formula can not refer to its own cell. Otherwise, You end up with an infinite loop, since the new value would cause another calculation... .
Use a helper column to calculate the value based on what you put in the other cell.
For Example:
Column A is a True or False, Column B contains a monetary value, Column C contains the following formula:
=B1
Now, to calculate that column B will be highlighted yellow in a conditional format only if Column A is True and Column B is greater than Zero...
=AND(A1=True,C1>0)
You can then choose to hide column C
For a non-volatile solution, how about for 2007+:
for cell =INDEX($A$1:$XFC$1048576,ROW(),COLUMN())
for column =INDEX($A$1:$XFC$1048576,0,COLUMN())
for row =INDEX($A$1:$XFC$1048576,ROW(),0)
I have weird bug on Excel 2010 where it won't accept the very last row or column for these formula (row 1048576 & column XFD), so you may need to reference these one short. Not sure if that's the same for any other versions so appreciate feedback and edit.
and for 2003 (INDEX became non-volatile in '97):
for cell =INDEX($A$1:$IV$65536,ROW(),COLUMN())
for column =INDEX($A$1:$IV$65536,0,COLUMN())
for row =INDEX($A$1:$IV$65536,ROW(),0)

- 22,383
- 32
- 112
- 130
In a VBA worksheet function UDF you use Application.Caller to get the range of cell(s) that contain the formula that called the UDF.

- 23,121
- 5
- 38
- 38
My current Column is calculated by:
Method 1:
=LEFT(ADDRESS(ROW(),COLUMN(),4,1),LEN(ADDRESS(ROW(),COLUMN(),4,1))-LEN(ROW()))
Method 2:
=LEFT(ADDRESS(ROW(),COLUMN(),4,1),INT((COLUMN()-1)/26)+1)
My current Row is calculated by:
=RIGHT(ADDRESS(ROW(),COLUMN(),4,1),LEN(ROW()))
so an indirect link to Sheet2!My Column but a different row, specified in Column A on my row is:
Method 1:
=INDIRECT("Sheet2!"&LEFT(ADDRESS(ROW(),COLUMN(),4,1),LEN(ADDRESS(ROW(),COLUMN(),4,1))-LEN(ROW()))&INDIRECT(ADDRESS(ROW(),1,4,1)))
Method 2:
=INDIRECT("Sheet2!"&LEFT(ADDRESS(ROW(),COLUMN(),4,1),INT((COLUMN()-1)/26)+1)&INDIRECT(ADDRESS(ROW(),1,4,1)))
So if A6=3 and my row is 6 and my Col is C returns contents of "Sheet2!C3"
So if A7=1 and my row is 7 and my Col is D returns contents of "Sheet2!D1"

- 21
- 2
I was looking for a solution to this and used the indirect one found on this page initially, but I found it quite long and clunky for what I was trying to do. After a bit of research, I found a more elegant solution (to my problem) using R1C1 notation - I think you can't mix different notation styles without using VBA though.
Depending on what you're trying to do with the self referenced cell, something like this example should get a cell to reference itself where the cell is F13:
Range("F13").FormulaR1C1 = "RC"
And you can then reference cells in relative positions to that cell such as - where your cell is F13 and you need to reference G12 from it.
Range("F13").FormulaR1C1 = "R[-1]C[1]"
You're essentially telling Excel to find F13 and then move down 1 row and up one column from that.
How this fit into my project was to apply a vlookup across a range where the lookup value was relative to each cell in the range without having to specify each lookup cell separately:
Sub Code()
Dim Range1 As Range
Set Range1 = Range("B18:B23")
Range1.Locked = False
Range1.FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-1],DATABYCODE,2,FALSE),"""")"
Range1.Locked = True
End Sub
My lookup value is the cell to the left of each cell (column -1) in my DIM'd range and DATABYCODE is the named range I'm looking up against.
Hope that makes a little sense? Thought it was worth throwing into the mix as another way to approach the problem.

- 543
- 5
- 14
Just for row, but try referencing a cell just below the selected cell and subtracting one from row.
=ROW(A2)-1
Yields the Row of cell A1 (This formula would go in cell A1.
This avoids all the indirect() and index() use but still works.

- 11
- 1