Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default TIP: Worksheets vs. Sheets (w/Charts) Count


Hi All

I'm rather new to VBA, so this is probably obvious to you pros.
just spent several hours figuring it out the hard way though, an
thought it worth sharing.

-Sheets.Count- counts all sheets in the workbook, including chart
which were created as sheets. -Worksheets.Count- counts only dat
sheets (true "worksheets"), not charts which also happen to be sheets
Use accordingly :)

You can try the following code in a new blank worksheet for
demonstration. I recommend stepping through it (F8) to understan
exactly what's happening.

Sub proExcelSheetCounts(

'Message Boxes show the WORKSHEETS count and the SHEETS coun
MsgBox "Excel thinks there are " & Worksheets.Count & " Worksheets
& Chr(10) & "and " &
Sheets.Count & " total sheets.

'Create a chart as a new shee
Sheets(2).Selec
Range("A1:B10").Selec
Charts.Ad
ActiveChart.Location Whe=xlLocationAsNewSheet
Name:="ChartIMade

MsgBox "Excel thinks there are " & Worksheets.Count & " worksheets
& Chr(10) & "and " &
Sheets.Count & " total sheets.

'Add a new data shee
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count

MsgBox "Excel thinks there are " & Worksheets.Count & " Worksheets
& Chr(10) & "and " &
Sheets.Count & " total sheets.

'Actions on different counted sheet
Sheets(Worksheets.Count).Selec
Cells(1, 1).Value = "I'm on the last WORKSHEETS count page.
Sheets(Sheets.Count).Selec
Cells(1, 1).Value = "I'm on the last SHEETS count page.

End Su

Cheers, and God Bless

--
EphesiansSi
-----------------------------------------------------------------------
EphesiansSix's Profile: http://www.excelforum.com/member.php...fo&userid=3572
View this thread: http://www.excelforum.com/showthread.php?threadid=56018

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default TIP: Worksheets vs. Sheets (w/Charts) Count

also try

charts.count

--
Regards,
Tom Ogilvy


"EphesiansSix" wrote:


Hi All,

I'm rather new to VBA, so this is probably obvious to you pros. I
just spent several hours figuring it out the hard way though, and
thought it worth sharing.

-Sheets.Count- counts all sheets in the workbook, including charts
which were created as sheets. -Worksheets.Count- counts only data
sheets (true "worksheets"), not charts which also happen to be sheets.
Use accordingly :)

You can try the following code in a new blank worksheet for a
demonstration. I recommend stepping through it (F8) to understand
exactly what's happening.


Sub proExcelSheetCounts()

'Message Boxes show the WORKSHEETS count and the SHEETS count
MsgBox "Excel thinks there are " & Worksheets.Count & " Worksheets"
& Chr(10) & "and " & _
Sheets.Count & " total sheets."

'Create a chart as a new sheet
Sheets(2).Select
Range("A1:B10").Select
Charts.Add
ActiveChart.Location Whe=xlLocationAsNewSheet,
Name:="ChartIMade"

MsgBox "Excel thinks there are " & Worksheets.Count & " worksheets"
& Chr(10) & "and " & _
Sheets.Count & " total sheets."

'Add a new data sheet
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)

MsgBox "Excel thinks there are " & Worksheets.Count & " Worksheets"
& Chr(10) & "and " & _
Sheets.Count & " total sheets."

'Actions on different counted sheets
Sheets(Worksheets.Count).Select
Cells(1, 1).Value = "I'm on the last WORKSHEETS count page."
Sheets(Sheets.Count).Select
Cells(1, 1).Value = "I'm on the last SHEETS count page."

End Sub

Cheers, and God Bless.


--
EphesiansSix
------------------------------------------------------------------------
EphesiansSix's Profile: http://www.excelforum.com/member.php...o&userid=35721
View this thread: http://www.excelforum.com/showthread...hreadid=560183


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default TIP: Worksheets vs. Sheets (w/Charts) Count


Brilliant, thanks Tom!


--
EphesiansSix
------------------------------------------------------------------------
EphesiansSix's Profile: http://www.excelforum.com/member.php...o&userid=35721
View this thread: http://www.excelforum.com/showthread...hreadid=560183

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update same charts in multiple sheets at once Div[_2_] Excel Worksheet Functions 1 January 28th 09 08:10 PM
Print embedded charts from several sheets Steve Charts and Charting in Excel 1 October 4th 06 03:17 AM
Create New WB with copy of Sheets 1 & 2 when sheets count reaches 100 Corey Excel Programming 5 June 26th 06 04:52 AM
Charts from Spread sheets nick g Excel Discussion (Misc queries) 3 July 27th 05 05:01 PM
Loop through sheets, deselect charts Daniel Bonallack[_2_] Excel Programming 4 October 28th 03 07:27 PM


All times are GMT +1. The time now is 06:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"