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

itr674

Well-known Member
Joined
Apr 10, 2002
Messages
1,786
Office Version
  1. 2016
Platform
  1. Windows
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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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
 
Upvote 0
Dave - worked perfect, and I was close this time to figuring out on my own--couldn't figure the x-3+1 part ... THANKS
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,497
Members
448,967
Latest member
visheshkotha

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