+ Reply to Thread
Results 1 to 3 of 3

Thread: Selection of multiple Charts

  1. #1
    Registered User
    Join Date
    12-22-2011
    Location
    Czech Rep.
    MS-Off Ver
    Excel 2010
    Posts
    2

    Selection of multiple Charts

    I need to modify selected charts when more than one chart is selected. Imagine that you have three charts and you select the 3rd and the 2nd. How can I find out which charts are selected?

    I tried Application.Selection.Item(idx).Chart but when idx=1 it does not return 1st selected chart (3rd chart) but 1st chart which is not selected. Strange thing is that in Watches window the item Application.Selection.Item(1) shows 1st selected chart (3rd chart) but in macro it returns 1st chart not 1st selected chart (3rd chart).
    Try to create three charts select the 3rd and the 2nd and trace this code:

    Sub TestSel()
        'Select Chart 3 and Chart 2 using Ctrl key
        Dim chrt(10) As String
        For idx = 1 To Application.Selection.Count
            chrt(idx) = Application.Selection.Item(idx).Name
        Next idx
        'Now see what is stored in chrt(1) and chrt(2)
        For idx = 1 To Application.Selection.Count
            MsgBox (chrt(idx)) 'Result should be Chart 3 and Chart 1 but it returns Chart 1 and Chart 2
        Next idx
    End Sub
    The problem is that Application.Selection.Item(idx) does not return selected charts but two 1st charts. Value Application.Selection.Count is correct.
    Any solution?
    Attached Files Attached Files

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,349

    Re: Selection of multiple Charts

    This will return the selected chart names

        For idx = 1 To Application.Selection.Count
            chrt(idx) = Application.Selection.ShapeRange.Item(idx).Name
        Next idx
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    12-22-2011
    Location
    Czech Rep.
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Selection of multiple Charts

    Thank you. Works great!

    And this is how to work with Charts:
    Application.Selection.ShapeRange.Item(idx).Chart

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0