Excel 2007 formula to return first cell reference in another cell's formula

Shea

New Member
Joined
Oct 1, 2011
Messages
10
Version: Excel 2007 WinXP

I'm basically looking for something almost like an inverse function to INDIRECT.
This function would first look at a cell's formula as a text string, parse out the first valid cell reference in A1 format, and return that cell as a text string.

Detail:
I have a spreadsheet with cells that point to other values. I would like to get only the row number from the first cell reference in the formula residing in a given cell. For example:

Suppose A1 has the formula =AL267.
and A2 has the formula =SUM(AL94:AL235)

I would like a formula in B1 that returns the text string, "AL267" so that I would know this is the first reference.

Ideally it could be dragged down to B2 such that it returns the text string "AL94" (and not "AL235") because AL94 is the first cell reference in A2's

Currently I am copying the formulas after hitting ctl+` and pasting that text into a text editor, followed by text operations to manipulate the results into the desired values. I was wondering if there might be a more elegant solution that didn't involve going out to notepad.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You need this UDF

Code:
Function GetFormula(Cell as Range) as String
   GetFormula = Cell.Formula
End Function

Press ALT+F11, then Insert-->Modul an enter above code.
Then for A1 you can use
=GetFormula(A1)

And for A2:
=MID(LEFT(GetFormula(A2),FIND(":",GetFormula(A2))-1),FIND("(",LEFT(GetFormula(A2),FIND(":",GetFormula(A2))-1))+1,5)
 
Upvote 0
Thanks. It was the cell.Formula property that I needed to know about. I had to do a little tweak to get read of the equals sign to use for my purposes, namely:

Code:
=RIGHT(getformula(A1),LEN(getformula(AT1))-1)

And I'm keeping the UDF in my personal workbook.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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