1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

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

Discussion in 'Business Applications' started by remboi, Jan 15, 2013.

Thread Status:
Not open for further replies.
Advertisement
  1. remboi

    remboi Thread Starter

    Joined:
    Nov 6, 2007
    Messages:
    25
    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
     
  2. CDHarm

    CDHarm

    Joined:
    May 26, 2011
    Messages:
    255
  3. remboi

    remboi Thread Starter

    Joined:
    Nov 6, 2007
    Messages:
    25
    Thanks for the reply, that's what I want to be able to do, but instead of having the code for the cap type etc. in the code I want to put this as text in a cell, so when i change the text in the cell and run the macro it will change it on the chart.

    e.g. in cell A1 I would enter msoLineLongDashDot (or some other format attribute) and in the code reference this with a command like sr.Border.LineStyle = A1

    i.e. can you take the text from a cell and use it in a command line?
     
  4. CDHarm

    CDHarm

    Joined:
    May 26, 2011
    Messages:
    255
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1085392

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice