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

itr674

Well-known Member
Joined
Apr 10, 2002
Messages
1,782
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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Dave Patton

Well-known Member
Joined
Feb 15, 2002
Messages
5,508
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,782
Office Version
  1. 2016
Platform
  1. Windows
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,181,645
Messages
5,931,195
Members
436,781
Latest member
acyiang

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