+ Reply to Thread
Results 1 to 3 of 3

VBA and Charts: best way to test for Chart vs. ChartObject

  1. #1
    Registered User
    Join Date
    08-11-2014
    Location
    Washington
    MS-Off Ver
    version 13
    Posts
    14

    VBA and Charts: best way to test for Chart vs. ChartObject

    The Chart/ChartObject object model is confusing. I have recorded macros for a chart and the code refers to the ActiveChart. When I tried writing code to go through all the tabs of the workbook, ActiveChart fails on some tabs.

    I have since learned that there are "Chart Sheets" with one chart which is the active chart. Then there are worksheets with one or more ChartObjects, which may or may not have the focus, and thus may or may not be an ActiveChart.

    Because of this distinction, I have to write code for two different situations, Chart vs. ChartObject.

    Is there a "best practice" way of iterating through the tabs of the workbook and testing to see if the tab is a Chart Sheet or a Worksheet with one or more Chart Objects?

    Thanks,

    Tom

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: VBA and Charts: best way to test for Chart vs. ChartObject

    Activechart is the chart that is active, is currently selected if a object or the tab if a chart sheet.
    There can only be a maximum of 1 activechart. And if no chart is selected it references nothing.

    in the example file are chart sheets, chart objects. With chart objects both on worksheets and chart sheets.

    this code will process them
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    08-11-2014
    Location
    Washington
    MS-Off Ver
    version 13
    Posts
    14

    Re: VBA and Charts: best way to test for Chart vs. ChartObject

    Thanks Andy! That was very helpful. Chart objects and their child member objects are confusing and that helped.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Code help with ChartObject failing, inconsistently.
    By mastro1978 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-11-2014, 02:12 PM
  2. Delete chartobject without deleting ALL charts on sheet
    By blh in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-14-2014, 07:01 AM
  3. [SOLVED] ChartObject will not add to the activesheet when data set is too large...
    By herbie226 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-13-2014, 11:28 AM
  4. [SOLVED] Passing chartobject as a parameter to sub
    By David Cohen in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-21-2005, 04:05 PM
  5. [SOLVED] Manipulating chartobject while workbook is shared.
    By Shelby Haynes in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2005, 07:05 PM
  6. [SOLVED] how to set a variable to a Chart? not ChartObject
    By Rich in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-06-2005, 03:05 PM
  7. [SOLVED] ChartObject Name Restricion or Excel Bug
    By Gaston in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-14-2005, 02:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1