EXCEL VBA Charts, Dynamic Chart Range

Sherifa

New Member
Joined
Oct 23, 2017
Messages
45
I have created two charts in my source worksheet Sheet4, but I want to adjust the range for 42 worksheets.
I'm less than a week old to Bloomberg, so didn't know the best way.
The data positioning is the same for all the worksheets.
I've added secondary axis etc, so want the copy and paste to be able to adjust to each worksheets data.
I want the charts to have the same formatting, and values etc, I don't want it to create a new charte
How can I go about this?

I've tried to add the range, but don't know what you meant or how to fill chart with actual values (rather binding it to sheet's range)

Rich (BB code):
Rich (BB code):
Sub SetSourceData()Dim Wkb As Excel.Workbook
Dim ws As Worksheet


 
 Set Wkb = ThisWorkbook
        ws_count = Wkb.Worksheets.Count
                
                     
        'Begin loop
        For i = 3 To ws_count
        
        Set TargetSheet = Wkb.Worksheets(i)
        
      Charts("AllDeals").SetSourceData Source:=Wkb.Worksheets(i).Range("q3:t14"), _
        PlotBy:=xlColumns
 
 
 Next
 
End Sub


Alternative code with error

Code:
[/B]Sub CopyCharts()



Dim Wkb As Excel.Workbook
Dim ws As Worksheet
Dim ws_count As Integer
Dim i As Integer




        Set Wkb = ThisWorkbook
        ws_count = Wkb.Worksheets.Count
        
Dim chDeals As Chart
Dim chVolume As Chart
Set chDeals = Worksheets("ALL") = Charts("ALLDeals")
Set chVolume = Worksheets("ALL").ChartObjects("ALL").Charts("ALLVolume")


                
                     
        'Begin loop
        For i = 4 To ws_count
        
        Set TargetSheet = Wkb.Worksheets(i)
        
        chDeals.Copy
        Range("q19").Select
        TargetSheet.Paste
            With ChartTitle = ws.Name
            End With
        
        Sheet4.ChartObjects("ALLVolume").Copy
        chVolume.Copy
        Range("aa19").Select
        TargetSheet.Paste
           With ChartTitle = ws.Name
            End With
      Next
      
End Sub


[B]
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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