+ Reply to Thread
Results 1 to 2 of 2

How can I change the marker style with a VBA loop?

  1. #1
    Registered User
    Join Date
    12-08-2004
    Posts
    31

    Question How can I change the marker style with a VBA loop?

    I have code that I want to change the marker style in a set of graphs. Each graph will have either 2,3 or 4 series. So I have established a range "Shapes" that contains the type of marker style for each series. (This way the graph is readable when printed in black and white)

    xlDiamond
    xlTriangle
    xlCircle
    xlSquare

    Sometimes there are 4 series in the graph, other times there are only 2 or 3 so I've used a loop to format each series.
    But when I run the following code I get an error "Unable to set MarkerStyle Property of the Series class"

    Please Login or Register  to view this content.
    What am I doing wrong. Does the data in my Shapes range have to be in a particular format? Any help would be greatly appreciated.

  2. #2
    Registered User
    Join Date
    12-08-2004
    Posts
    31

    Solved!

    An answer posted elsewhere by datagopher:

    Make sure you are applying the MarkerStyle property to the correct ChartTypes. The xlColumn Chart doesn't have markers so it won't accept the MarkerStyle property. Also, you only have 4 values for the MarkerStyles so you probably don't need to fill from a range, just define them in your code. The important thing here is to make sure the array values don't end up as Strings like "xlMarkerStyleDiamond" with the quotes included. I have used the method below with success:

    Dim MyMarkers(4) As Variant

    MyMarkers(1) = xlMarkerStyleTriangle
    MyMarkers(2) = xlMarkerStyleDiamond
    MyMarkers(3) = xlMarkerStyleCircle
    MyMarkers(4) = xlMarkerStyleSquare

    With Charts("Display Chart").SeriesCollection(2)
    .ChartType = xlLine
    .MarkerStyle = MyMarkers(2)
    .MarkerBackgroundColorIndex = RGB(0,0,255)
    .MarkerForegroundColorIndex = RGB(255,0,0)
    .MarkerSize = 10
    End With

    Have a great afternoon!

    A special thanks to datagopher for the above solution.

+ 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