Results 1 to 3 of 3

VBA chart conditional formatting

Threaded View

  1. #1
    Registered User
    Join Date
    11-24-2009
    Location
    Toledo, Spain
    MS-Off Ver
    Excel 2007
    Posts
    2

    VBA chart conditional formatting

    Hi, I am a novice at VBA and have a question about formatting marker colors in a chart based on the values in a column of my spreadsheet.

    I have results of analysis of soil samples in a worksheet with 27 columns and 360 rows. The column labels are for year, plot, and then 25 soil analysis variables. Each row is for one sample from one year--there are 8 years of data. There are 45 samples for each year--one sample for each of 45 plots, labeled "1" through "45" (in column D). What I have done is to use VBA to produce a X-Y chart for each soil variable: "TC" for Total Carbon, for example. The x-axis is categorical: "1" to "45" for each plot. The y-axis is the level of carbon in the soil sample for that plot. The chart therefore shows stacked markers above each plot number; one marker for each of the 8 years. I have stacked 25 charts--one for each variable--using VBA, by making the code for one variable's chart and then just copying down the VBA window 24 times, changing the refernce columns and names for each chart, and the chart's location on the sheet.

    This works fine, but what I'd like to do is to have different marker colors for different years. I am thinking that the .FormatConditions object is the way to go (I have Excel 2007), but I can't figure out how to use it. Can anyone help me out with this?

    I have posted below my VBA script for one of the charts. It's probable that this script shows how little VBA I know--I used the Macro Recorder a bit and copied from forums a bit.

    Thank you!

    ______________________
    Dim ChtTC As ChartObject
    Set ChtTC = ActiveSheet.ChartObjects.Add(5, 2970, 600, 150)
    With ChtTC.Chart
    .ChartType = xlXYScatter
    .SetSourceData Source:=Sheets("data").Range("ac5:ac320,e5:e320")
    .SeriesCollection(1).Values = "='data'!$ac$6:$ac$320"
    .SeriesCollection(1).XValues = "='data'!$d$6:$d$320"
    .SeriesCollection(1).Name = "TC"
    .SeriesCollection(1).MarkerSize = 4

    With .Axes(xlCategory)
    .MinimumScale = 0
    .MaximumScale = 45
    .CrossesAt = 0
    End With

    With .Axes(xlValue)
    .MinimumScale = 0
    .MaximumScale = 60
    ' .CrossesAt = 0
    End With

    .HasLegend = False
    .HasTitle = True
    .ChartTitle.Text = "TC"
    .ChartTitle.Select
    With Selection
    .Font.Size = 8
    .Top = 0
    .Left = 0
    End With
    End With
    Last edited by hmmm...; 12-09-2010 at 07:26 PM.

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