Consulting

Results 1 to 7 of 7

Thread: Solved: Count tabs in Workbook

  1. #1

    Smile Solved: Count tabs in Workbook

    Hi,

    I am looking for help in runnning a quick macro that counts the number of tabs in a workbook, without necessarily knowing the names of those tabs or their order.

    For example workbook with tabs:
    "Control"
    "Sheet1"
    "Sheet2"
    "Sheet4"

    would return 4 and
    "Sheet4"
    "Control"
    "Sheet2"
    "Sheet1"
    would return 4.

    Any help would be great

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

    Activeworkbook.Sheets.Count
    [/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
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]
    Sub test()
    Dim sh, i as long
    MsgBox Worksheets.Count '(excludes charts)
    'or
    MsgBox Sheets.Count

    'Exclude hidden sheets
    For Each sh In Sheets
    If sh.Visible = True Then i = i + 1
    Next
    MsgBox i
    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'

  4. #4
    Thats great thanks for your help

    Sarah

  5. #5
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    This example might also be useful to you.

    I did not make it...can't even remember where I got it from now. I'd give credit to the maker if I could remember who it was
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You got it from Rob Bovey (directly or indirectly).
    ____________________________________________
    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

  7. #7
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    Quote Originally Posted by xld
    You got it from Rob Bovey (directly or indirectly).
    It would be indirectly. Someone sent this to me as a resource when I was trying to figure out how to grab worksheet names.

    Good resource though
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


Posting Permissions

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