SheetName Function

  • Thread starter =?iso-2022-jp?B?RVhDRUwbJEIhIRsoQk5FV1M=?=
  • Start date
?

=?iso-2022-jp?B?RVhDRUwbJEIhIRsoQk5FV1M=?=

here is my function

Function SheetName(x) As String '
Application.Volatile
SheetName = ActiveSheet.name
End Function '

what i want to do is to get the sheet name in in which a cell (like
=SheetName(0)) is in.

not the. name of ActiveSheet.

what should i do.
 
H

Haldun Alay

Function SheetName(x) As String
Application.Volatile True
If x <= 0 Then
SheetName = "Worksheet number must be greater than 0"
Exit Function
End If
With Application.Caller.Parent.Parent
If x > .Worksheets.Count Then
SheetName = "Warning: There is no worksheet"
Else
SheetName = .Worksheets(x).Name
End If
End With
End Function


--
Haldun Alay
"EXCEL$B!!(BNEWS" <[email protected]>, haber iletisinde ?unlar? yazd?:[email protected]...
here is my function

Function SheetName(x) As String '
Application.Volatile
SheetName = ActiveSheet.name
End Function '

what i want to do is to get the sheet name in in which a cell (like
=SheetName(0)) is in.

not the. name of ActiveSheet.

what should i do.
 
A

Andrew B

Hi
Not sure what you want - do you want to find the cell that contains the
sheet name ?


[C3] = activesheet.name will put the sheet name into any cell you
specify, lik C3. More info needed....

Andrew B
 
A

Ardus Petus

Maybe someting like this:

"------------------------------
Function sheetname(rng As Range) As String
sheetname = rng.Worksheet.Name
End Function
'------------------------------

HTH
 
G

Guest

I'm not sure what the variable "x" is for in your example.
But try this:

Function SHEETNAME() As String
Dim s As Object
Application.Volatile
Set s = Application.Caller
SHEETNAME = s.Parent.Name
End Function

You type in a cell:
=SHEETNAME()

The formula will return the sheetname of the sheet where you typed the
formula.

Regards,
Edwin Tam
(e-mail address removed)
http://www.vonixx.com
 
G

Guest

thanks to all of you.
i have thought it out ,like Mr Edwin Tam suggested to me,
i will do better with his advice
thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top