Worksheets - need to put number in column next to sheetname?

itr674

Well-known Member
Joined
Apr 10, 2002
Messages
1,778
I am using the code below to list worksheet names in column H. I want a number, starting with 1 for the first sheet name, to be listed next to sheet namr in column G.<pre>Sub WS_List3()
Dim wks As Worksheet
Dim x As Integer 'declares x as an interger

With Sheet2.Cells
.Range("G:G").ClearContents
.Font.Name = "Arial"
.Font.Size = 8
.IndentLevel = 1
End With

x = 2
For Each wks In Worksheets
x = x + 1
Sheet2.Cells(x, 8) = wks.Name
Next wks

End Sub</pre>
This message was edited by em on 2002-10-18 00:49
This message was edited by em on 2002-10-18 00:49
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Dave Patton

Well-known Member
Joined
Feb 15, 2002
Messages
4,971
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
try adding one line after line that adds the
.Name

edit to
Sheets("Sheet2").Cells(x, 7) = x - 2
from
Sheets("Sheet2").Cells(x, 7) = x - 3 + 1

If the sheet is not named Sheet2, change the edit back to relevant sheet addressing.
This message was edited by Dave patton on 2002-10-18 10:29
 

itr674

Well-known Member
Joined
Apr 10, 2002
Messages
1,778
Dave - worked perfect, and I was close this time to figuring out on my own--couldn't figure the x-3+1 part ... THANKS
 

Forum statistics

Threads
1,144,312
Messages
5,723,649
Members
422,508
Latest member
Lordkit1

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