Solved

Excel sheet names

Posted on 2009-03-31
12
219 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
  • 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Spell Check in VB6 13 52
Dynamic Vlookup Function Formula Help 4 17
Getfiles in vb.net 28 25
EXCEL formula help required 3 15
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now