Macro for updating charts

jevi

Active Member
Joined
Apr 13, 2010
Messages
339
Office Version
  1. 2016
Platform
  1. Windows
Hi All,
I am using this macro to update 4 graphs that I have created manually. The data that I have created the graphs is from B9:O54, the problem is that every 10 days I need to add other data so B55:O55 and I wanted the graphs to be updated automatically. This macro doesn't do it but it sounds only updates data if they are changed but always with the range B9:O54.

Is there a way to do it? My table of data is formatted as conditional formatting.

Thank you

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim tbl As ListObject
    Dim cht As ChartObject
    
    ' Definisci il nome della tabella
    Set tbl = ThisWorkbook.Worksheets("NomeFoglio").ListObjects("NomeTabella") ' Modifica "NomeFoglio" con il nome del foglio e "NomeTabella" con il nome della tabella formattata
    
    ' Verifica se il cambiamento coinvolge la tabella
    If Not Intersect(Target, tbl.DataBodyRange) Is Nothing Then
        ' Aggiorna tutti i grafici
        For Each cht In ThisWorkbook.Worksheets("NomeFoglio").ChartObjects ' Modifica "NomeFoglio" con il nome del tuo foglio
            cht.Chart.SetSourceData tbl.DataBodyRange
        Next cht
    End If
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You don't need a macro at all to get this organised.
What you need to do is to make the datatable a Table (Format as Table - in the Home menu)

Then create your graph.

Now every time you add a row to your table, the graph is automatically adjusted. presto
 
Upvote 0
Solution
Thank you...yes I did try that but was not working as I had the charts made before the table so I created the table and then I did again the charts from start and it worked great:).
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,035
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top