+ Reply to Thread
Results 1 to 6 of 6

Macro to automatically change chart line style based on cell text

  1. #1
    Registered User
    Join Date
    01-15-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Question Macro to automatically change chart line style based on cell text

    Hi,

    My VBA/Macro knowledge is very basic, but I am able to record macros and edit them. I have a scatter plot (with 5 series) and I want to automatically change the line style (i.e. solid or dashed etc.) depending on the text in a cell. This is what I tried, but I cannot get the code to reference the cell which contains the text:

    --------------------------------------------------------------

    Sub Macro14()
    '
    ' Macro14 Macro
    '
    '
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.SeriesCollection(1).Select
    With Selection.Format.Line
    .Visible = msoTrue
    .DashStyle = msoLineSolid
    End With
    End Sub


    --------------------------------------------------------------

    For the line ".DashStyle = msoLineSolid" I tried ".DashStyle = Range("A7").Select" but this does not work.

    Is there a simpler way to set-up a macro to format graphs automatically based on a cell content/format/colour, does anyone know a good guide to do this?

    Thanks,
    Magpie

  2. #2
    Forum Contributor
    Join Date
    01-03-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Macro to automatically change chart line style based on cell text

    I have no experience with charts using VBA but maybe try:

    Please Login or Register  to view this content.
    but I give completely no guarantee that will work

  3. #3
    Registered User
    Join Date
    01-15-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro to automatically change chart line style based on cell text

    Thanks for the reply, I tried that also but I get the same error (Run Time Error '13' Type mismatch)

  4. #4
    Forum Contributor
    Join Date
    01-03-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Macro to automatically change chart line style based on cell text

    Well, I expected that - this would be to easy
    But I was really curious if it is possible to do, so I did some research and created a macro you may see in attached file. I know it's not perfect, but maybe you will find it helpful in some way.

    Please note: you must change word "Wykres 1" to "chart1" (or whatever the default chart name is in your workbook) in code, because I use a polish version of Excel.
    Attached Files Attached Files
    Last edited by Sbarro79; 01-15-2013 at 10:56 PM. Reason: missing word

  5. #5
    Registered User
    Join Date
    01-15-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro to automatically change chart line style based on cell text

    Quote Originally Posted by Sbarro79 View Post
    Well, I expected that - this would be to easy
    But I was really curious if it is possible to do, so I did some research and created a macro you may see in attached file. I know it's not perfect, but maybe you will find it helpful in some way.

    Please note: you must change word "Wykres 1" to "chart1" (or whatever the default chart name is in your workbook) in code, because I use a polish version of Excel.
    Thanks for the response, that works really well.

    Can I ask where you found the research for this? I have been trying to do what you have done but make it so it applies to all the charts and series on the worksheet and for marker types, but haven't found anything that can help.

    NM

  6. #6
    Forum Contributor
    Join Date
    01-03-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Macro to automatically change chart line style based on cell text

    Sorry for very late reply - I've been a bit busy recently.
    I'm glad to hear you found it helpful. I understand that writing "research" was misleading but the truth is I only searched through some websites for how to change chart dash style using VBA and the rest of code is my own idea (created using trial and error or what if method). That's the whole secret

+ 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