PDA

View Full Version : Solved: VBA Reporting Too Many Worksheets



Opv
03-17-2010, 06:22 PM
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?

mbarron
03-17-2010, 06:33 PM
Do you have any hidden sheets in the workbook?
Run this to check:
Sub showAll()
Dim i As Integer
For i = 1 To Sheets.Count
Sheets(i).Visible = True
Next
End Sub

Paul_Hossler
03-17-2010, 06:34 PM
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

Opv
03-17-2010, 06:44 PM
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


Do you have any hidden sheets in the workbook?
Run this to check:
Sub showAll()
Dim i As Integer
For i = 1 To Sheets.Count
Sheets(i).Visible = True
Next
End Sub

Opv
03-17-2010, 06:46 PM
Thanks!



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