Results 1 to 7 of 7

Change chart color bars VBA code assistance

Threaded View

  1. #1
    Registered User
    Join Date
    11-10-2011
    Location
    Chatsworth, California
    MS-Off Ver
    Excel 2010
    Posts
    41

    Question Change chart color bars VBA code assistance

    VBAChartColorChange.xlsm
    I am trying some VBA code that is supposed to change the colors of a chart depending on what colors the datasheet contains in column "A". (eg. "A1" is green then the color bar in the chart for the data pertaining to "A1" should be green also.)

    It is not working. I get an error code: Object variable or With block variable not set." I have searched the internet but am not able to find a similar situation to mine. And I still have a hard time searching this site - I couldn't find anything about an error 91.

    (I have attached my workbook - and threw the code in below in case that is what someone likes to work with also.) Thanks - and I will reply to any answers; and let the person know if got a solution out of thier reply.
    Sub ColorByCategoryLabel()
        Dim rPatterns As Range
        Dim iCategory As Long
        Dim vCategories As Variant
        Dim rCategory As Range
           Set rPatterns = ActiveSheet.Range("A1:A11")
              With ActiveChart.SeriesCollection(1)
                vCategories = .XValues
              For iCategory = 1 To UBound(vCategories)
           Set rCategory = rPatterns.Find(What:=vCategories(iCategory))
           .Points(iCategory).Interior.ColorIndex = rCategory.Interior.ColorIndex
       Next
             End With
    End Sub
    Last edited by BGiffin2004; 12-14-2011 at 01:00 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