How To List All Worksheet Names In Excel - Except a Specific Worksheet?

dougmarkham

Active Member
Joined
Jul 19, 2016
Messages
252
Office Version
  1. 365
Platform
  1. Windows
Hi Folks,

I have found this macro which lists all the worksheet names within a workbook.

Code:
[COLOR=#0077AA][FONT=inherit]Sub[/FONT][/COLOR][COLOR=black][FONT=Consolas] SheetNames[/FONT][/COLOR][COLOR=#999999][FONT=inherit]([/FONT][/COLOR][COLOR=#999999][FONT=inherit])[/FONT][/COLOR][COLOR=black][FONT=Consolas]
[/FONT][/COLOR][COLOR=#0077AA][FONT=inherit]For[/FONT][/COLOR][COLOR=black][FONT=Consolas] i [/FONT][/COLOR][COLOR=#A67F59][FONT=inherit]=[/FONT][/COLOR][COLOR=#990055][FONT=inherit]1[/FONT][/COLOR][COLOR=#0077AA][FONT=inherit]To[/FONT][/COLOR][COLOR=black][FONT=Consolas] Sheets.Count
[/FONT][/COLOR][COLOR=black][FONT=Consolas]Cells[/FONT][/COLOR][COLOR=#999999][FONT=inherit]([/FONT][/COLOR][COLOR=black][FONT=Consolas]i[/FONT][/COLOR][COLOR=#999999][FONT=inherit],[/FONT][/COLOR][COLOR=#990055][FONT=inherit]1[/FONT][/COLOR][COLOR=#999999][FONT=inherit])[/FONT][/COLOR][COLOR=#A67F59][FONT=inherit]=[/FONT][/COLOR][COLOR=black][FONT=Consolas] Sheets[/FONT][/COLOR][COLOR=#999999][FONT=inherit]([/FONT][/COLOR][COLOR=black][FONT=Consolas]i[/FONT][/COLOR][COLOR=#999999][FONT=inherit])[/FONT][/COLOR][COLOR=black][FONT=Consolas].[/FONT][/COLOR][COLOR=#0077AA][FONT=inherit]Name
[FONT=inherit]Next[/FONT][COLOR=black][FONT=Consolas] i [/FONT][/COLOR]
[/FONT][/COLOR][COLOR=#0077AA][FONT=inherit]End[/FONT][/COLOR][COLOR=#0077AA][FONT=inherit]Sub[/FONT][/COLOR]

Let's say the worksheet I'm running this macro in is called 'Master' and there are 4 other worksheets in the workbook: White, Brown, Yellow, and Green. I wish to modify this code so that it returns the names of the other worksheets, not including 'Master'.

E.g., in A1 down...
White
Brown
Yellow
Green.

This will be then used as part of a reference for a formula, so I'm looking for a way of stopping the macro from including 'Master' in the list?

Would you please help me modify this code?

Kind regards,

Doug.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Doug

Hi

Code:
Sub SheetNames()
J = 1
For i = 1 To Sheets.Count
If (Sheets(i).Name <> "Master") Then
    Cells(J, 1) = Sheets(i).Name
    J = J + 1
End If
Next i
End Sub

Regards


Ed
 
Upvote 0
Doug

Hi

Code:
Sub SheetNames()
J = 1
For i = 1 To Sheets.Count
If (Sheets(i).Name <> "Master") Then
    Cells(J, 1) = Sheets(i).Name
    J = J + 1
End If
Next i
End Sub

Regards


Ed


Hi Ed,

Thanks for the help: that works perfectly!
Seems I need to look up how "i" in VBA as many of the macros I've found useful contain it.

Many thanks,

Doug.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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