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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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