Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 19th, 2005, 01:24 AM
Authorized User
 
Join Date: Jun 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Macro to count the no. of sheets

Hi, anyone know how to write the codes to count the total no. of sheets within a workbook?

Please advise.

Thanks :D

 
Old August 19th, 2005, 01:41 AM
Authorized User
 
Join Date: Sep 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try the following code

ActiveWorkbook.Worksheets.Count

it will return you total numbers of worksheets in the active workbook.



It is always safe to assume, not that the old way is wrong, but that there may be a better way...
*************************
Rekha
 
Old August 19th, 2005, 02:10 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you may want to count all sheets, only worksheets or only chart sheets...

Sub mycount()
mysheets = ActiveWorkbook.Sheets.Count
myworksheets = ActiveWorkbook.Worksheets.Count
mycharts = ActiveWorkbook.Charts.Count
MsgBox (mysheets & " sheets and " & myworksheets & " worksheets and " & mycharts & " Charts")

End Sub

cheers

Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
calling to xlam macro from macro inside xlsb SteveB Excel VBA 0 June 30th, 2008 06:43 PM
copy sheets jgrant Beginning VB 6 0 March 26th, 2007 01:42 PM
is there any in built function to count page count g.tamilselvan MySQL 1 February 15th, 2006 07:43 AM
Count, sum, count a value, return records CongoGrey Access 1 April 18th, 2005 02:25 PM
Macro to replace and updating sheets in workbooks vjs2445 Excel VBA 1 August 16th, 2004 02:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.