Results 1 to 4 of 4

Thread: Get Total Worksheets In Workbook

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    2

    Get Total Worksheets In Workbook

    Hi. Im completely new to VB, but heres what Im tring to do. I want to get a count of the total worksheets in my workbook. Then I would like cycle through these sheets & compare some cells. Any advise / help is apricated

  2. #2
    Lively Member JustinLabenne's Avatar
    Join Date
    Jul 2005
    Location
    Ohio
    Posts
    64

    Re: Get Total Worksheets In Workbook

    You can use a function to return the sheet count

    VB Code:
    1. Option Explicit
    2.  
    3. Public Function ShtCount() As Long
    4.     Application.Volatile True
    5.     ShtCount = ActiveWorkbook.Worksheets.Count
    6. End Function

    It can be used just like a formula,

    Not sure about comparing cells though, Need more info about what you want.

    Got some to share?
    Justin Labenne
    www.jlxl.net

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    2

    Re: Get Total Worksheets In Workbook

    Cool, that worked. So now that I have a count of all sheets how can I make them active one at a time to look at values in each sheets cells?

    Thanks for your help.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Get Total Worksheets In Workbook

    You can actually use a For Each loop, like this:
    VB Code:
    1. For Each MySheet IN ActiveWorkbook.Worksheets
    2. 'work with the cells here  (MySheet.Name will return the name of the sheet):
    3.       Msgbox MySheet.Cells(1,1).Value, , MySheet.Name
    4.  
    5.     Next MySheet

Posting Permissions

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



Click Here to Expand Forum to Full Width