Monday, July 19, 2010

Workbook Tab Count

Follow the below procedure to count the number of Tabs in the workbook.

* Go to the code in "ThisWorkBook". You can find the code by

-- pressing ALT+F11

-- Right-clicking on "ThisWorkBook" on the left

-- Left clicking on view code.

Then paste in the following code:

Private Sub Workbook_Open()
Sheets("NameOfSheet").Cells(1, 1).Value = Worksheets.Count
End Sub

* Save the code and close.
* Save the file as “Excel Macro Enabled Workbook (.xlsm)” and close.

When the worksheet opens, it'll count the number of worksheets and put
the value in a specified cell. So in this case if you have a sheet
named NameOfSheet it will put a number in Row 1, Column A.

Note: If it doesn’t show the count after opening the sheet, look for
the security warning on the left top which says “Macros have been
disabled.”

Solution:

* Click on Options
* Select “Enable this content”
* Click “OK”

1 comment: