Solved

Excel sheet names

Posted on 2009-03-31
12
225 Views
Last Modified: 2013-12-17
Hi Guys
I am planning to do a report and i need a list of all sheetnames in one colums,is there a function that i can use to get sheet names
F(1) = Sheet#1's name
F(2) =Sheet#2's name
and so on
0
Comment
Question by:titorober23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 2
12 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 24028559
Hi,
Do you mean as a formula in a cell?
0
 

Author Comment

by:titorober23
ID: 24028561
yes
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 75 total points
ID: 24028573
The following UDF will return sheet names.  Be advised that it will not update automatically when you change
a sheet name, but it should update at the next recalc.
Function SheetName(SheetIndex As Long)
 
    Application.Volatile
    SheetName = ThisWorkbook.Sheets(Sheet Index).Name
 
End Function

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24028581
titorober23,

Note also that that is a VBA, and not a C#, function...

Regards,

Patrick
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24028596
Typo...

Function SheetName(SheetIndex As Long)
 
    Application.Volatile
    SheetName = ThisWorkbook.Sheets(SheetIndex).Name
 
End Function
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24028613
Hm, it appears that it is automatically updating on a sheet rename--must be because the renaming itself
forces a recalc :)
0
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 50 total points
ID: 24028648
You could use a UDF like this:
 

Function SheetName(lngIndex As Long) As String
SheetName = Application.Caller.Parent.Parent.Sheets(lngIndex).Name
End Function

Open in new window

0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 24028669
Oops, should have refreshed!
0
 

Author Comment

by:titorober23
ID: 24028704
it is giving me #NAME?
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24028717
titorober23,

Rory's use of the Caller method is a good one--my approach works breaks down if the UDF is used in an add-in
or personal macro workbook.  However, I think you need the Volatile bit to ensure updates when you change the
sheet names and/or order.  Combining the best bits of both...

Regards,

Patrick
Function SheetName(lngIndex As Long)
 
    With Application
        .Volatile
        SheetName = .Caller.Parent.Parent.Sheets(lngIndex).Name
    End With
 
End Function

Open in new window

0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24028726
rorya said:
>>Oops, should have refreshed!

No worries, Rory--indeed, your post pointed to a better way of figuring out which Workbook to process :)
0
 
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 75 total points
ID: 24028736
titorober23 said:
>>it is giving me #NAME?

Did you put the code in a regular VBA module, and not a sheet or ThisWorkbook?
Are macros enabled?
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question