+ Reply to Thread
Results 1 to 4 of 4

Macro to create a graph when a button is pressed

  1. #1
    Registered User
    Join Date
    02-06-2014
    Location
    Guildford
    MS-Off Ver
    Excel 2010
    Posts
    5

    Macro to create a graph when a button is pressed

    Morning,

    I have a table of data which contains company names, the number of high risk policies, number of low risk policies, and the percentage of high risk policies (compared to total policies).

    What I want to do is for people to be able to select up to six of these companies and press a button that says 'create graph' and it creates a graph which shows the number of high risk and low risk in a stacked bar, and the percentage on a separate axis as a line.
    I know how to manually create this graph no problem, but to be able to dynamically create one from selected companies would be awesome. If this is possible would you please help me with some VBA code????

    To start with I have created six drop downs where you can select the company name as I image the macro will need to know which companies' data to look for in the source table.

    Thank you in advance!

    Jemma

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,606

    Re: Macro to create a graph when a button is pressed

    Start with sample layout .
    Prepare a graph.
    start recording macro
    delete all graph series and add niew ones.
    stop recording.

    You will have a good starting point for graph preparation from selected series.
    Only major change in registered code will be: select not always the same data but selected by user.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    02-06-2014
    Location
    Guildford
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro to create a graph when a button is pressed

    I'm afraid I am a VBA beginner so would require some code help. I tried your suggestion and all I get is

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,606

    Re: Macro to create a graph when a button is pressed

    So as you see in your registered code the main lines are
    Please Login or Register  to view this content.
    this part deletes one series from the graph it can be repeated as many times as neeeded

    Please Login or Register  to view this content.
    this one adds new all series. it is not the way you want/need it you rather want to add series one by one - this way it will be possible to show selected ones only.

    By the way, after reading the opening post once again - I think there are big chances, you do not need macro at all. It can be probably pretty well done with dynamic named ranges. If you are not eager to macro preparation think of preparing small sample workbook with dummy data and post a thread in pivot/graphs subforum with sample attached.

+ 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. ontime macro button activates all sheets in woorkbook intead of just the one it is pressed
    By peter renton in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-01-2013, 02:57 PM
  2. How can I create a limit for how many macro buttons can be pressed ?
    By BonBonz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-19-2012, 10:38 AM
  3. [SOLVED] Toggle Button & getting the postion of the just pressed button
    By NugentS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2012, 11:58 AM
  4. automatically create a spinner and link it when a button is pressed
    By jamesleggit in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-23-2005, 11:07 AM

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