+ Reply to Thread
Results 1 to 20 of 20

macro to draw a vertical line on a graph

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    macro to draw a vertical line on a graph

    I have an issue drawing a vertical line on graphs that changes dynamically as per the data on their respective pivot tables. The line should be on or next to 15-20 range. Please see the attached spreadsheet. The range might or might not appear in the chart. But the line should always be on or after 20.

    I have 3 charts on the same spreadsheet that needs a line. I have come across a code on internet, but donno how to edit for my case here.
    Please Login or Register  to view this content.
    Please kindly help.

    Many Thanks and Kind regards
    Attached Files Attached Files
    Last edited by kbaruin; 10-05-2012 at 11:30 AM.

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

    Re: macro to draw a vertical line on a graph

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    Your main problem is the code is for a Date axis and you have category axis.
    This will add line after 2nd category.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: macro to draw a vertical line on a graph

    Andy

    Sorry edited my post. I tried your code but doesn't work. It just adds a dotted line on all the charts but not on the 20 line.

    Please can you help with the code.

    Thanks
    Bhargavi

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

    Re: macro to draw a vertical line on a graph

    What's the 20 line?
    As I said your axis is not a value axis, it is category.

    You would need to decipher the axis labels in some way in order to determine the numeric value of a individual category.

  5. #5
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: macro to draw a vertical line on a graph

    It is actually a value but I grouped the column to show a range on the chart. You can see its Pivot table. I want the line to be displayed at 20 days so that the graph shows all the ABCs thats generated after 20 days needs concerned. I manually added a red line on the charts, that is how I wanted but by macro code.

    Your code just adds a dotted line after 2nd categery irrespetive of how many days. Is it possible to get how I wanted??

    Thanks

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

    Re: macro to draw a vertical line on a graph

    Please Login or Register  to view this content.
    Some of the lines will be pretty meaningless as the value does not exist on the chart.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: macro to draw a vertical line on a graph

    Andy

    Thanks Very much. It works as I wanted. Just one last amendment needed. Can this be Red color line and a bit thick line please???

    Thanks again

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

    Re: macro to draw a vertical line on a graph

    Can you not try using the code you had in the first post to format the line?
    The routine has a variable, shpLine, that references the line on the chart.

  9. #9
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: macro to draw a vertical line on a graph

    Andy

    I tried the code in your last post which works fine. Can you point me where to change in the code for the color and thichkness of the line?? I am not sure where to change for the shpLine.

    Thanks

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

    Re: macro to draw a vertical line on a graph

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: macro to draw a vertical line on a graph

    Hi Andy

    Is there a way where I can choose which charts to have the line??

    Thanks

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

    Re: macro to draw a vertical line on a graph

    probably.

    Currently the code loops through all the chart objects on a sheet.

    Please Login or Register  to view this content.
    You just need to specify what chart object to pass to the AddDatum routine.

  13. #13
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: macro to draw a vertical line on a graph

    I want the chart 13, chart 14, chart 15 on the sheet to have the line, how do I state this in the code??

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

    Re: macro to draw a vertical line on a graph

    not really putting much effort into this are you

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: macro to draw a vertical line on a graph

    Type mismatch error
    I am a VBA beginner and your code is very complicated to understand. thats why need your help in editing

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

    Re: macro to draw a vertical line on a graph

    But you are not showing us any of the stuff you are doing. You just keep on asking for more and more, including editing of stuff that has already been posted.

    Take your last post, you have not shown the code you used, you have not said where exactly the error occurs.

  17. #17
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: macro to draw a vertical line on a graph

    Sorry about that. I am trying to call the AddDatum function for only charts that I wanted the line. The error occurs at the 3rd line.

    Please Login or Register  to view this content.

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

    Re: macro to draw a vertical line on a graph

    Oversight on my posted code.

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    09-11-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    81

    Re: macro to draw a vertical line on a graph

    Thanks ever so much Andy. It works now.

    Apologies for too many questions.

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

    Re: macro to draw a vertical line on a graph

    Glad to hear it

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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