• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Using sheet names as variables

murugaraj

New Member
We can use CELL function to retrieve various data about a cell and use them in formulas too. Is there a similar way to use sheet names?

I have a workbook with productivity of each employee in a single table (a table with 20 employee names with their daily productivity). There is another workbook with 20 worksheets, each sheet for an employee. The sheet is names after the employee name. I want to use the employee name by referring to the sheet name. Something like:

if(Name="name of this sheet", ..., ...). Is that possible? Is there any roundabout, if not?

Thanks for your insights.

Murugaraj
 
I generally use a macro to put sheet names into a known cell on each sheet

like A1
 
Oh, but I'm yet to learn macros. My present knowledge of macros is recording and editing them to a certain level. I think it's time I try that too. Thanks, Hui.
 
or you could use

=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,256)

Make sure you save the worksheet before you use this
 
You could use the fo;;owing function:


Function ShName(ByRef range As Variant)

ShName = range.Parent.Name

End Function


on the worksheet enter =ShName(A1)
 
If you have sheet names in one column (or at least something you can rely on to determine the name of the sheet) you can use the INDIRECT() function like this (assuming B3 is the sheet name :


Code:
= INDIRECT( "'" & B3 & "'!somecellref" )


This formula will give you the value of the "somecellref" cell.


Hope this helps too


Cyril Z.
 
I use Hui's formula all the time! Works great. I even contatenate the filename with other info when needed.


-- sparkyvega
 
Hui,

I can't resist but wonder how smart your formula is. thanks a ton.

@cyrilz: your trick is good, too; but it is a little roundabout. Thanks for sharing.

Murugaraj
 
Back
Top