Results 1 to 4 of 4

Thread: Change Color Of Series In A Bar Chart Based On Selection Of DropDowns

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    45
    Rep Power
    0

    Change Color Of Series In A Bar Chart Based On Selection Of DropDowns

    I would like to use a dropdown list to run macro to color the bar chart, what is the code to run the dropdown list in D1 and D4 by the color name "Blue" etc, instead of running on E1 & E4 which select the color code.

    and how to color the D1 cell when the content in dropdown list is selected, now it cannot color the cell, only when i run macro from the Run Macro button, it can color
    Attached Files Attached Files
    Last edited by mrprofit; 04-16-2014 at 07:18 PM.

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Remove all your existing code, and just use this in the sheet module.

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Not Intersect(Target.Cells(1), Range("D1:E1,D4:E4")) Is Nothing Then
            Application.EnableEvents = False
        End If
        If Not Intersect(Target.Cells(1), Range("E1,E4")) Is Nothing Then
            Target.Cells(1, 0).Value = Range("G" & Application.Match(Target.Cells(1).Value, Range("H1:H10"), 0)).Value
            Target.Cells(1, 0).Resize(, 2).Interior.ColorIndex = Target.Cells(1).Value
        ElseIf Not Intersect(Target.Cells(1), Range("D1,D4")) Is Nothing Then
            Target.Cells(1, 2).Value = Range("H" & Application.Match(Target.Cells(1).Value, Range("G1:G10"), 0)).Value
            Target.Cells(1).Resize(, 2).Interior.ColorIndex = Target.Cells(1, 2).Value
        End If
        ColorBar_1
        ColorBar_2
        Application.EnableEvents = True
        
    End Sub
    Sub ColorBar_1()
        
        With ActiveSheet.ChartObjects("Chart 1026").Chart.SeriesCollection(1)
            .Shadow = False
            .InvertIfNegative = False
            With .Border
                .Weight = xlThin
                .LineStyle = xlAutomatic
            End With
            With .Interior
            .ColorIndex = Sheets("Sheet2").Range("$E$1").Value
            .Pattern = xlSolid
            End With
        End With
        
    End Sub
    
    Sub ColorBar_2()
        
        With ActiveSheet.ChartObjects("Chart 1026").Chart.SeriesCollection(2)
            .Shadow = False
            .InvertIfNegative = False
            With .Border
                .Weight = xlThin
                .LineStyle = xlAutomatic
            End With
            With .Interior
            .ColorIndex = Sheets("Sheet2").Range("$E$4").Value
            .Pattern = xlSolid
            End With
        End With
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Member
    Join Date
    Apr 2014
    Posts
    45
    Rep Power
    0
    Thank you for your time, It works
    Last edited by mrprofit; 04-17-2014 at 10:10 PM.

  4. #4
    Member
    Join Date
    Apr 2014
    Posts
    45
    Rep Power
    0
    Just found a problem, it won't work when the sheet is PW protected, any way around this?

Similar Threads

  1. Change Chart Title According To Source Data Selection
    By terrybloome in forum Excel Help
    Replies: 4
    Last Post: 12-02-2013, 03:19 PM
  2. Replies: 8
    Last Post: 08-17-2013, 04:03 AM
  3. Change Data Series In Chart Using Drop-Down List
    By raybugge in forum Excel Help
    Replies: 2
    Last Post: 07-06-2013, 03:02 PM
  4. Replies: 1
    Last Post: 05-03-2013, 04:41 PM
  5. Color Chart Series VBA
    By Admin in forum Download Center
    Replies: 0
    Last Post: 04-29-2011, 11:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •