Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a worksheet name using Excel VBA

Tags:

excel

vba

I would like to create an user-defined function in Excel that can return the current worksheet. I could use the

sheetname = ActiveSheet.Name

But the problem with this is, it works and suddenly it starts to get different sheet name. For example, instead of SHEET I LOVE YOU it returns SHEET I HATE YOU.

Is there anyway to fix this - or it might possible because I think it can not be static but varies?

like image 563
user2103670 Avatar asked Oct 11 '13 16:10

user2103670


People also ask

How do I find a specific sheet name in Excel?

Right-click the ◀︎▶︎ at the left of the sheet tabs to bring up the Activate window... It provides a sequential list of the sheet names which is scrollable. Select the one you want then click the OK button.

How do I fetch a sheet name in a cell?

Step 1: Type “CELL(“filename”,A1)”. The cell function is used to get the full filename and path. This function returns the filename of . xls workbook, including the sheet name.


1 Answers

Function MySheet()

  ' uncomment the below line to make it Volatile
  'Application.Volatile
   MySheet = Application.Caller.Worksheet.Name

End Function

This should be the function you are looking for

like image 143
mucio Avatar answered Oct 21 '22 13:10

mucio