Ask Your Question
0

How do I access the current sheet name in formula (to use in INDIRECT) [closed]

asked 2013-04-25 17:41:31 +0100

Jim Trigg gravatar image

I want to create a formula that I can use on multiple sheets that will do a vlookup on the table named the same as the current sheet. How do I access the current sheet name in the formula?

The idea is to do the following formula:

=INDIRECT("VLOOKUP(A"&COL()&","&SHEETNAME()&",2,0)")

but as far as I can tell there is no function that returns the name of a sheet.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2015-10-30 20:54:31.883571

Comments

I was tired when I posted the question or I would have remembered that indirect only takes an address, not a formula, and given that there's no reason to indirect the local cell reference. The problem with the Sheet() approach is that I want it to be transparent - each sheet references a separate table. The SheetName range is exactly what I'm looking for, though the function actually becomes vlookup(a1,indirect(sheetname),2,0) - note that the SheetName range needs to be indirected to work.

Jim Trigg gravatar imageJim Trigg ( 2013-05-14 15:44:30 +0100 )edit

3 Answers

Sort by » oldest newest most voted
1

answered 2013-04-25 19:58:06 +0100

m.a.riosv gravatar image

Hi Jim Trigg,

the JohsSUN's defined function is fine and simple, working with/without a sheet number, allowing reference between different sheets.

But your formula does not work, in the way how it is constructed. INDIRECT() function it is not an evaluator for formulas, only addresses as text are right.

The formula can be:

=VLOOKUP(INDIRECT("A"&COLUMN()),INDIRECT(MID(CELL("filename"),FIND("#$",CELL("filename"))+2,LEN(CELL("filename")))),2,0)

I have replaced the defined function with a little formula, as another way to get the sheet name.

As this formula to get the sheet name has not range address, there is no problem in give it a name (in the same way as you define a name for a range), for work in any sheet.
Define a range as:
SheetName = MID(CELL("filename"),FIND("#$",CELL("filename"))+2,LEN(CELL("filename")))
The formula:
=VLOOKUP(INDIRECT("A"&COLUMN()),SheetName,2,0)

I think easier is define a name range without the sheet name in it, what can work in any sheet. Define a range as:
DataRange = $h$1:$w$100 (e.g.)
The formula:
=VLOOKUP(INDIRECT("A"&COLUMN()),DataRange,2,0)

Sample file

edit flag offensive delete link more
1

answered 2013-04-25 19:20:07 +0100

razon_22 gravatar image

You can use the =SHEET() function. It returns the sheet number, so you could add a sheet number column to your table and do the vlookup from it.

edit flag offensive delete link more
1

answered 2013-04-25 18:43:22 +0100

JohnSUN gravatar image

It seems to me that your SHEETNAME() is

Function SheetName(Optional nSheet)
If IsMissing(nSheet) Then
    SheetName = ThisComponent.getCurrentController().getActiveSheet().getName()
Else
    SheetName = ThisComponent.getSheets().getByIndex(nSheet-1).getName()
EndIf
End Function
edit flag offensive delete link more

Comments

Good afternoon.

JohnSUN (Apr 25 '13):

Function SheetName(Optional nSheet)...
End Function
It did the trick, for me. I just had to put: =SheetName(Row()) and get what I needed;thanks.

Morvan gravatar imageMorvan ( 2016-07-02 20:32:16 +0100 )edit

Question Tools

1 follower

Stats

Asked: 2013-04-25 17:41:31 +0100

Seen: 13,112 times

Last updated: Apr 25 '13