SOLVED

how to reference the current sheet name in an function?

New Contributor

I am aware that you can reference other sheets in a function, but how do you reference the current sheet in one?

 

IF(Current_sheet_name="user template", value_if_true, value_if_false)

 

Thanks!

2 Replies

@Needsleep 

You can use the CELL function to reference the current sheet name in an Excel function.

Here’s how:

  1. Click on the cell where you want to reference the current sheet name.
  2. Type =CELL("filename") in the formula bar and press Enter.
  3. The result will be a string that contains the full path and name of the workbook, followed by a square bracket, followed by the sheet name in quotes. For example: [Book1.xlsx]Sheet1.
  4. To extract just the sheet name from this string, you can use the MID function. Here’s an example formula that returns the current sheet name: =MID(CELL("filename"),FIND("]",CELL("filename"))+1,255).
  5. Now you can use this formula to reference the current sheet name in your function like this: =IF(MID(CELL(\"filename\"),FIND(\"]\",CELL(\"filename\"))+1,255)=\"user template\", value_if_true, value_if_false).

 

I hope this helps! 

best response confirmed by Needsleep (New Contributor)
Solution

@Needsleep 

 

(the workbook must be saved)

If you run Excel 365:

=IF(TEXTAFTER(CELL("filename",A1),"]") = "user template", value_if_true, value_if_false)

with other versions:

=IF(RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-SEARCH("]",CELL("filename",A1))) = "user template", value_if_true, value_if_false)