Consulting

Results 1 to 5 of 5

Thread: Solved: VBA Reporting Too Many Worksheets

  1. #1
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location

    Solved: VBA Reporting Too Many Worksheets

    I have a line of code which simply generates a msgbox that reports the number of worksheets in the active workbook. The line is as follows:

    msgbox (ActiveWorkbook.Sheets.Count)

    There are only two sheets in the workbook but his code results in a count of three every time it's run. If I insert an additional sheet and then run the code, it reports four sheets instead of three. What could be accounting for this?

  2. #2
    VBAX Mentor
    Joined
    Jun 2004
    Posts
    363
    Location
    Do you have any hidden sheets in the workbook?
    Run this to check:
    [VBA]Sub showAll()
    Dim i As Integer
    For i = 1 To Sheets.Count
    Sheets(i).Visible = True
    Next
    End Sub[/VBA]

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Is one Hidden or VeryHidden? Go to the VBE and look at the propoerties of the worksheets in the workbook to see.

    Also I think Sheets includes all sheets, charts, etc. What does Worksheets.count give?

    Paul

  4. #4
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Thanks. After running this code, it revealed a sheet that I have no clue how it got there. I certainly didn't create it. I guess my brother must have created it and forgot about it before he sent me the sheet. At any rate, deleting that previously hidden sheet corrected the problem.

    Thanks.

    Opv

    Quote Originally Posted by mbarron
    Do you have any hidden sheets in the workbook?
    Run this to check:
    [vba]Sub showAll()
    Dim i As Integer
    For i = 1 To Sheets.Count
    Sheets(i).Visible = True
    Next
    End Sub[/vba]

  5. #5
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Thanks!


    Quote Originally Posted by Paul_Hossler
    Is one Hidden or VeryHidden? Go to the VBE and look at the propoerties of the worksheets in the workbook to see.

    Also I think Sheets includes all sheets, charts, etc. What does Worksheets.count give?

    Paul

Posting Permissions

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