Consulting

Results 1 to 12 of 12

Thread: List of Worksheet Tab Names

  1. #1

    List of Worksheet Tab Names

    Hi All

    Is there any way of creating a list of all the sheet names (i.e Tab names) in a particular workbook. Say I am working in on a Workbook having Sheets 1 to 10. I wouls like to list (by Excel function or thru macro) all the worksheet names at a single place in say worksheet 1. Pl. help./Rajesh

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    For i = 1 To Worksheets.Count
    Worksheet("Sheet1").Cells(i,"A").Value = Worksheets(i).Name
    Next i
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location
    dear xld
    thats what i made out of your code.can you symplfy it.can you show how to add in coplumn B a list of cell B2 of each sheet?
    [VBA]
    Sub addlistofsheets()
    Dim ash As Worksheet
    If SheetExists("list") = False Then GoTo err
    For i = 1 To Worksheets.Count
    Worksheets("list").Cells(i, "A").Value = Worksheets(i).name
    Range("A:A").Columns.autofit
    Next i
    Exit Sub
    err:
    If MsgBox("list of sheets is unavailable,create one?", vbOKOnly + vbCritical, "TOC") = vbOK Then
    Set ash = Sheets.Add
    ash.name = "list"
    ash.Move before:=Sheets(1)
    For i = 1 To Worksheets.Count
    Worksheets("list").Cells(i, "A").Value = Worksheets(i).name
    Range("A:A").Columns.autofit
    Next i
    End If
    End Sub

    [/VBA]
    thanks
    moshe

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Have you tried this?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Thanx very much XLD for tje solution...its working

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Moshe,
    Something like
    [VBA]
    Sub ListB2()
    Dim sh As Worksheet, i as Long
    For Each sh In Worksheets
    If sh.Index <> ActiveSheet.Index Then
    i = i + 1
    Cells(i, 2) = sh.Cells(2, 2)
    End If
    Next
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location
    could you merge them into one?
    [VBA]
    Sub addlistofsheets()
    Dim ash As Worksheet
    If SheetExists("list") = False Then GoTo err
    For i = 1 To Worksheets.Count
    Worksheets("list").Cells(i, "A").Value = Worksheets(i).name
    Range("A:B").Columns.autofit
    Next i
    Exit Sub
    err:
    If MsgBox("list of sheets is unavailable,create one?", vbOKOnly + vbCritical, "TOC") = vbOK Then
    Set ash = Sheets.Add
    ash.name = "list"
    ash.Move before:=Sheets(1)
    For i = 1 To Worksheets.Count
    Worksheets("list").Cells(i, "A").Value = Worksheets(i).name
    Range("A:B").Columns.autofit
    Next i
    End If
    End Sub
    Sub ListB2()
    Dim sh As Worksheet, i As Long
    Sheets("list").Select
    For Each sh In Worksheets
    If sh.index <> ActiveSheet.index Then
    i = i + 1
    Cells(i + 1, 2) = sh.Cells(2, 2)
    End If
    Next
    End Sub
    [/VBA]
    moshe

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Sub addlistofsheets()
    Dim ash As Worksheet
    On Error Resume Next
    Set ash = Sheets("list")
    If err = 9 Then
    Set ash = Worksheets.Add
    ash.Name = "List"
    err.Clear
    End If
    i = 3
    For Each sh In Worksheets
    If sh.Index <> ash.Index Then
    i = i + 1
    Cells(i + 1, 1) = sh.Name
    Cells(i + 1, 2) = sh.Cells(2, 2)
    End If
    Next
    ash.Range("A:B").Columns.AutoFit
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location
    can any one show how to add a sum formula at the bottom of column B?
    thanks
    moshe

  10. #10
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I suggest you start a new thread for this question lior03
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  11. #11
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location
    hello
    let me take this a little further.suposs i have a workbook with say 6 sheets
    january to june.each sheet's column A contains pepole name.column B contain numerical value say wgae paid.can i use excel vba to create sheets for each man and 6 rows with six wages and s sum formula bellow?
    thanks
    moshe

  12. #12
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Hi Moshe,

    Please start a new thread. This has absolutely nothing to do with "List of all worksheet tab names".
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •