+ Reply to Thread
Results 1 to 6 of 6

How to write VBA code that waits for the user to select a chart?

  1. #1
    Registered User
    Join Date
    08-06-2013
    Location
    the boonies
    MS-Off Ver
    Excel 2007
    Posts
    46

    Cool How to write VBA code that waits for the user to select a chart?

    I wrote some code that currently only works if a chart is already selected/activated before running the code.
    Could you share a VBA example that waits for the user to activate a chart (or a shape object) before proceeding?
    Is this an event-handling issue?

    I tried assigning my subroutine to a rectangle shape-object on the same worksheet as the chart (poor man's button), but unfortunately this shape becomes the active object (stealing "active" status from the chart), so when it calls the sub, the sub just exits with an error. Would assigning this sub to a User Form button have the same outcome? I haven't experimented with making my own GUIs yet.

    Thanks,
    Geophysicist
    Attached Files Attached Files
    Last edited by geophysicist; 08-22-2013 at 08:15 AM. Reason: attaching spreadsheet

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Are you looking for something that's triggered by a user selecting a chart?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-06-2013
    Location
    the boonies
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: How to write VBA code that waits for the user to select a chart?

    I want the user's selection to be passed to the code.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    For that you can use Selection and check what's selected with TypeName.

  5. #5
    Registered User
    Join Date
    08-06-2013
    Location
    the boonies
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: How to write VBA code that waits for the user to select a chart?

    code example?

  6. #6
    Registered User
    Join Date
    08-06-2013
    Location
    the boonies
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: How to write VBA code that waits for the user to select a chart?

    Let me try to explain more clearly...

    Once I execute the code, at a certain point I want it to pause until it receives a mouse click on a chart from the user (which would activate that chart), and then proceed with the rest of the instructions.

    I've done a fair bit of research in the last two evenings, and have not yet found an example that shows code this general. It's always "exit sub if no chart was selected prior to executing the sub", or "set mychart equal to a known chart, and activate it (if not already active) before proceeding." In my case, I do not want to hardwire a known chart in the code, but rather, wait for the user to select a chart with a mouse click, and use that action as the chart selection to pass to "ActiveChart".

    Again, if you have a coding example of this type of thing, or you know this to be beyond the capabilities of VBA, please post!

    Cheers,
    g
    Last edited by geophysicist; 08-23-2013 at 02:58 AM.

+ 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. Replies: 0
    Last Post: 06-11-2013, 05:14 PM
  2. How do i code a VBA to ask the user to select which file to use
    By kenadams378 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 05-16-2012, 07:26 PM
  3. Can't write code to find last data row in excel user form
    By stevegrobertson in forum Excel General
    Replies: 8
    Last Post: 02-24-2012, 10:16 PM
  4. Code to prevent user to Select COLUMNS but allow to select ROWS
    By tengrosita in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-05-2011, 03:46 AM
  5. Create chart where user select part of data
    By Endorphin in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 10-23-2008, 06:50 AM

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