+ Reply to Thread
Results 1 to 5 of 5

Execute data label coloring code when drop down list changed

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-23-2013
    Location
    Hungary
    MS-Off Ver
    Excel 2013
    Posts
    331

    Execute data label coloring code when drop down list changed

    Hi,

    I would need your help regarding a worksheet change event.

    On Chart worksheet in cell C6 I have drop down list (with material numbers) and when this value change then the MinMaxLabelColoring code (<= working fine alone) should be called and executed, but this is not working.

    Could you please help me to figure out the right way?

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Target.Address = Worksheets("Chart").Range("$C$6") Then
            Call MinMaxLabelColoring
        End If
        
    End Sub
    Sub MinMaxLabelColoring()
    Dim ws As Worksheet
    Dim ch As ChartObject
    Dim i As Long, j As Long
    Dim maxVal As Long, minVal As Long
    Dim Ser1Color As Long, Ser2Color As Long
    
        Set ws = Sheets("Evaluation")
        maxVal = [MIN(IF(NOT(ISNA(MAX)),MAX))]
        minVal = [MIN(IF(NOT(ISNA(MIN)),MIN))]
                
        Sheets("Chart").Activate
                
        Set ch = Sheets("Chart").ChartObjects("Chart1")
        Ser1Color = 13998939
        Ser2Color = 8355711
                
        With ch.Chart
            For i = 1 To 2
                For j = 1 To .SeriesCollection(i).Points.Count
                    Debug.Print .SeriesCollection(i).Points(j).DataLabel.Font.Color
                    If .SeriesCollection(i).Points(j).DataLabel.Caption = minVal Then
                                .SeriesCollection(i).Points(j).DataLabel.Font.Color = vbRed
                            ElseIf .SeriesCollection(i).Points(j).DataLabel.Caption = maxVal Then
                                .SeriesCollection(i).Points(j).DataLabel.Font.Color = rgbGreen
                        Else
                        If i = 1 Then
                                .SeriesCollection(i).Points(j).DataLabel.Font.Color = Ser1Color
                            ElseIf i = 2 Then
                                .SeriesCollection(i).Points(j).DataLabel.Font.Color = Ser2Color
                        End If
                    End If
                Next j
            Next i
        End With
    
    End Sub
    Thank you in advance the reply!

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: Execute data label coloring code when drop down list changed

    Didn't check your MinMaxLabelColoring procedure. But your Worksheet_Change() event is off as you are comparing address string with range object.

    You should change code to something like...
        If Target.Address = "$C$6" Then
            Call MinMaxLabelColoring
        End If
    Edit: Other options.
        If Not Intersect(Target, [C6]) Is Nothing Then
            Call MinMaxLabelColoring
        End If
    Last edited by CK76; 03-20-2017 at 02:03 PM.

  3. #3
    Forum Contributor
    Join Date
    12-23-2013
    Location
    Hungary
    MS-Off Ver
    Excel 2013
    Posts
    331

    Re: Execute data label coloring code when drop down list changed

    Hi CK76,

    I checked your options but the problem is still open on my side.
    Could you see the attached file?
    Attached Files Attached Files

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: Execute data label coloring code when drop down list changed

    You have Worksheet_Change event in Module1. Put it in "Chart" sheet module.

    Looks to be working fine on my end when code is moved to "Chart" sheet module.

  5. #5
    Forum Contributor
    Join Date
    12-23-2013
    Location
    Hungary
    MS-Off Ver
    Excel 2013
    Posts
    331

    Re: Execute data label coloring code when drop down list changed

    Thank you very much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Min and Max data label coloring
    By Villalobos in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 03-17-2017, 09:00 AM
  2. [SOLVED] Run macro when data validation drop down box is changed code bug help
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2016, 08:21 AM
  3. [SOLVED] VBA Code to copy cell value on another sheet on drop down list changed
    By aftermath09 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-16-2015, 12:27 AM
  4. [SOLVED] Broken drop-down list due to its contents being changed with a macro
    By mdovey in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-13-2014, 01:10 PM
  5. Replies: 4
    Last Post: 08-31-2012, 08:02 AM
  6. Drop down list to execute macro
    By dagindi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-05-2010, 05:16 PM
  7. [SOLVED] When does Code Execute on a List Box?
    By John Baker in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2005, 05:06 PM

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