BlogCell.Docs
HomePostsShowcaseAbout MeContact

Command Palette

Search for a command to run...

BlogCell.Docs

Practical VBA macros and documentation for Excel and finance professionals.

Explore

  • Home
  • Posts
  • Showcase
  • About Me
  • Contact

Connect

  • Email
  • Instagram
  • LinkedIn

Legal

  • Privacy Policy
  • Terms of Service
  • Disclaimer

© 2026 Harsh C. All rights reserved.

HomeBlogVBA Code - List All Sheets
VBA

VBA Code - List All Sheets

A VBA macro to list all sheet names in a workbook into a single column for further automation.

Harsh C

Harsh C

February 2, 2025 · 3 min read

See it in action

Why should I use?

There are many instances where using dynamic functions becomes necessary to automate tasks and easily update data changes. In such cases, a basic requirement is listing your sheet names.

Why is listing sheet names necessary?

Listing sheet names is essential for several reasons:

  1. Organization: It helps in keeping track of all the sheets in a workbook, especially when dealing with large and complex files.
  2. Navigation: Quickly navigate to specific sheets without manually searching through tabs.
  3. Automation: Facilitates the automation of tasks such as data consolidation, reporting, and analysis by referencing sheet names programmatically.
  4. Error Checking: Ensures that all necessary sheets are present and correctly named, reducing the risk of errors in data processing.

By listing sheet names, you can streamline your workflow and enhance productivity, making it easier to manage and manipulate your data.

There are many instances when we need to list the names of the sheets in the workbook, and this task can be done using a VBA macro.

Example

Suppose you have a list of products and their sales data, each listed on separate sheets within your workbook. The sheet names are as follows (I used the VBA code to list the name of sheets):

Category
Laptop
Personal Computer
Server
Custom Build Computer
Software
Service

Now, you want to get the sales data from all the products available in individual sheets. How do you get it? The answer is simple:

You have 2 options:

  1. Manually copy and paste the sales value from each sheet.
  2. Use Excel functions with sheet references.

I choose option 2, and here are the results:

CategorySalesFunction
Laptop305000=INDIRECT("'"&A1&"'!"&"B5")
Personal Computer427000=INDIRECT("'"&A2&"'!"&"B5")
Server6138000=INDIRECT("'"&A3&"'!"&"B5")
Custom Build Computer14065000=INDIRECT("'"&A4&"'!"&"B5")
Software561000=INDIRECT("'"&A5&"'!"&"B5")
Service130000=INDIRECT("'"&A6&"'!"&"B5")

Impact of VBA Code and Functions

Task - Fetch data from respective sheets

ParticularsTime Taken to completeRemarks
Manual Method7 MinutesListing all Products then manually copying and pasting the data, chances of error is high
VBA code and functions1 MinuteVBA code listed the product at once, inserted the function and dragged to all products that's it. No error

Well, that's why the VBA code becomes necessary to list all the sheets in one column within the fractions of seconds, and using it for further automation.

VBA Code

Here's the VBA code we are discussing:

Sub M5_ListAllSheets()
Dim ws As Worksheet
Dim Counter As Integer
 
Counter = 0
 
For Each ws In ActiveWorkbook.Worksheets
    ActiveCell.Offset(Counter, 0).Value = ws.Name
    Counter = Counter + 1
Next ws
End Sub

How to Use This Code

To use this code in Excel:

  1. Open Excel and press ALT + F11 to open the Visual Basic for Applications (VBA) editor.
  2. In the VBA editor, insert a new module by right-clicking on any of the items in your project and selecting Insert > Module.
  3. Copy and paste the above code into the module window.
  4. Close the VBA editor and return to Excel.
  5. Select a cell where you want to start listing your sheet names.
  6. Press ALT + F8, choose M5_ListAllSheets, and click Run.
PreviousVBA Code - Sampling ToolNextVBA Code - Rename Sheets

On this page

  • See it in action
  • Why should I use?
  • Why is listing sheet names necessary?
  • Impact of VBA Code and Functions
  • VBA Code
  • How to Use This Code
Back to blog