Return portion of Formula?

  • Thread starter Thread starter Ken
  • Start date Start date
K

Ken

Excel2003 ... Range D15:D54 now contains formulas similar to:

Cell D15 contains ... =MAX('Simpson, F'!R$15:R$300)
Cell D16 contains ... =MAX('Clause, S'!R$15:R$300))
Cell D17 contains ... =MAX('Alonglastname, C'!R$15:R$300))
etc (Name of WS chgs on each Row)

In Range A15:A54 ... I would like a Formula that will return the WS Name
contained in formula Range D15:D54.

A15 return "Simpson, F"
A16 return "Clause, S"
A17 return "Averylonglastname, C"

Thanks ... Kha
 
Try this one-line UDF:

Function sheetref(r As Range) As String
sheetref = Split(r.Formula, "'")(1)
End Function


UDFs are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.

To use the UDF from the normal Excel window, just enter it like a normal
Excel Function, for example =sheetref(D15)

To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To learn more about UDFs, see:

http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
 
Back
Top