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

dougmarkham

Board Regular
Joined
Jul 19, 2016
Messages
229
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.
 

Some videos you may like

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

edmitchell

Board Regular
Joined
Dec 18, 2017
Messages
62
Office Version
  1. 365
Platform
  1. Windows
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
 

dougmarkham

Board Regular
Joined
Jul 19, 2016
Messages
229
Office Version
  1. 365
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,108
Messages
5,599,760
Members
414,336
Latest member
Nicolas2465

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
Top