+ Reply to Thread
Results 1 to 8 of 8

Bubble Chart Not Updating Based on Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    09-10-2019
    Location
    Edinburgh, UK
    MS-Off Ver
    Office 365 (Mac and Windows)
    Posts
    27

    Bubble Chart Not Updating Based on Macro

    As per the attached workbook I have a bubble chart on sheet 'Prioritisation' which is taking its series data points from the sheet 'Master Copy'. I also have a macro which is designed to update the bubble colours based on the cell colour of column AJ on the 'Master Copy' worksheet.

    The macro is:

    Option Explicit
    Sub ColorChartSeries()
    Dim iRow As Long, iCol As Long
    Dim theBubbles As Range
    Dim theChart As Chart
    Dim theSeries As Series
    Dim thePoint As Point
    
    Set theChart = ActiveChart
    
    If (theChart.ChartType <> xlBubble And theChart.ChartType <> xlBubble3DEffect) Then
        MsgBox "This works only for bubble charts!"
        End
    End If
    
    For Each theSeries In theChart.SeriesCollection
        Set theBubbles = Range(theSeries.BubbleSizes)
        iRow = 1
        For Each thePoint In theSeries.Points
            thePoint.Format.Fill.ForeColor.RGB = Intersect(Worksheets("Master Copy").Range("AJ:AJ"), theBubbles.Rows(iRow).EntireRow).DisplayFormat.Interior.Color
            iRow = iRow + 1
        Next thePoint
    Next theSeries
    
    End Sub
    As you will see the bubble colours do not reflect the cell and also do not update if I use the slicers associated to the 'Master Copy' worksheet
    Attached Files Attached Files

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Bubble Chart Not Updating Based on Macro

    Because the rows in the table, which are used in the chart, may not be contiguous when a filter is applied you need to use Areas/Cells to get the corresponding bubble cell from the range.

    Sub ColorChartSeries()
    Dim iRow As Long, iCol As Long
    Dim theBubbles As Range
    Dim theChart As Chart
    Dim theSeries As Series
    Dim thePoint As Point
    Dim areaIndex As Long
    Dim cellIndex As Long
    
    Set theChart = ActiveChart
    
    If (theChart.ChartType <> xlBubble And theChart.ChartType <> xlBubble3DEffect) Then
        MsgBox "This works only for bubble charts!"
        End
    End If
    
    For Each theSeries In theChart.SeriesCollection
        Set theBubbles = Range(theSeries.BubbleSizes).SpecialCells(xlCellTypeVisible)
        areaIndex = 1
        cellIndex = 1
        For Each thePoint In theSeries.Points
            If cellIndex > theBubbles.Areas(areaIndex).Cells.Count Then
                areaIndex = areaIndex + 1
                cellIndex = 1
            End If
            thePoint.Format.Fill.ForeColor.RGB = Intersect(Worksheets("Master Copy").Range("AJ:AJ"), theBubbles.Areas(areaIndex).Cells(cellIndex).EntireRow).DisplayFormat.Interior.Color
            cellIndex = cellIndex + 1
        Next thePoint
    Next theSeries
    
    End Sub
    If the conditional formatting changes the colour to display when filtered then you will need to capture the calculate event of the table sheet in order to rerun the format macro.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    09-10-2019
    Location
    Edinburgh, UK
    MS-Off Ver
    Office 365 (Mac and Windows)
    Posts
    27

    Re: Bubble Chart Not Updating Based on Macro

    Thanks Andy. That works perfectly until I use the slicer and new data is loaded and then the bubble colours are wrong and I need to manually run the macro again for these to be corrected. Any thoughts on how this can be corrected so that the macro doesn't have to be manually run?

  4. #4
    Registered User
    Join Date
    09-10-2019
    Location
    Edinburgh, UK
    MS-Off Ver
    Office 365 (Mac and Windows)
    Posts
    27

    Re: Bubble Chart Not Updating Based on Macro

    Also I don't know if there is any way for the macro to run without having to phyically click on the chart itself first?

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Bubble Chart Not Updating Based on Macro

    As I mentioned, "capture the calculate event of the table sheet", in order to run the macro.

    Replace Activechart with worksheets("Prioritisation").chartobjects(1).chart

  6. #6
    Registered User
    Join Date
    09-10-2019
    Location
    Edinburgh, UK
    MS-Off Ver
    Office 365 (Mac and Windows)
    Posts
    27

    Re: Bubble Chart Not Updating Based on Macro

    Thanks Andy, in reference to "capture the calculate event of the table sheet" I am actually not sure how to do this but based on your description I am not sure it is the issue. Using the slicers does not change the conditional cell colour of any cell, these are based on a formula from data points only not related to the chart/slicers.

    The issue seems to be that if I use the slicer the bubble colours are incorrect until I re-run the macro and then they are corrected, I would just like them to be correct without having to re-run the macro manually.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Bubble Chart Not Updating Based on Macro

    Right click Master Copy sheet and add the following event code

    Private Sub Worksheet_Calculate()
    ColorChartSeries
    
    End Sub

  8. #8
    Registered User
    Join Date
    09-10-2019
    Location
    Edinburgh, UK
    MS-Off Ver
    Office 365 (Mac and Windows)
    Posts
    27

    Re: Bubble Chart Not Updating Based on Macro

    Thank you so much Andy, it works perfectly!!!!

+ 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] Bubble chart fill based on 4th variable value?
    By tx_us in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 02-28-2014, 03:30 PM
  2. Color a bubble chart based on a range of numbers
    By bradv23 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 11-18-2013, 05:03 AM
  3. Edit bubble behind another bubble in bubble chart (2007)
    By JayUSA in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 07-14-2009, 03:10 PM
  4. [SOLVED] How do I link a bubble in the bubble graph to another chart?
    By Pradnya Purandare in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 07-17-2006, 12:25 AM
  5. How do i add text labels to each bubble on bubble chart?
    By bazza in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 12-07-2005, 12:10 AM
  6. Making a Bubble Chart based on n-values matrix
    By Haydar in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 08-08-2005, 07:05 PM
  7. [SOLVED] ho to change in the bubble chart the bubble position and size
    By laszlo in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 03-25-2005, 01:06 PM
  8. Replies: 0
    Last Post: 02-20-2005, 04: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