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

dougmarkham

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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

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
231
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,128,129
Messages
5,628,869
Members
416,347
Latest member
AT2021

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