Sheet Name VBA

Presly

New Member
Joined
Nov 13, 2013
Messages
2
hy all,
i'm got VBA code for taking a sheetname into cell, but problem is it's not run automaticaly, so everytime i change the sheetname the i must recalculated to make the sheetname on cell change.
this is the code :

Code:
Public Function sheetname(ByVal target As Range)
sheetname = target.Worksheet.Name
End Function

whit that code i can take the sheetname with this formula =sheetname(A1), please help me to make this run automatic
i'm newbie to VBA :confused:
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Welcome to the forum.

You can use the following formula that will update in real time. Note that the file must be saved.

=TRIM(RIGHT(SUBSTITUTE(CELL("filename",A1),"]",REPT(" ",255)),255))
 
Upvote 0
Or if you insist on the UDF maybe try this:
Code:
Public Function sheetname(ByVal target As Range)
Application.Volatile
sheetname = target.Worksheet.Name
End Function
 
Upvote 0
Try Adding Application.Volatile as the first line of your Function.

Sorry! I didn't see that same response already posted.
 
Upvote 0

Forum statistics

Threads
1,215,463
Messages
6,124,963
Members
449,200
Latest member
indiansth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top