VBA copied chart keeps on pointing to original data, VBA relinking charts to nesource data

dastr

New Member
Joined
Mar 23, 2013
Messages
2
Problem wt VBA - copied chart keeps on pointing to original data, VBA relinking charts to new source data
Dear all,

I have a chart linked to a source data on sheet "Pattern". I want to copy and paste the chart and the table on multiple sheets. I have managed so far to create the multiple sheets in VBA but when I copy and paste the table and charts on the newly created worksheets, I either have all the newly pasted charts linking to the original data
(table) on worksheet "Pattern" or I paste the tables but not the charts.

Can someone help? Ideally I would like to paste a chart and a table on a new worksheet (say WS "English") and have the chart on WS English being linked to the table on the same worksheet?

Here I am attaching the example.
Thanks in advance.






</PRE>
Code:
Sub CreateManyWorksheetsAndCopyPattern()
    'Create the worksheets for all regions
    For Each cell In Selection
        ThisWS = cell.Value
        Worksheets.Add after:=Worksheets(Worksheets.Count)
        ActiveSheet.Name = ThisWS
    Next cell
    

' COPY THE PATTERN
    
Worksheets("Pattern").Range("A3:Z10").Copy Destination:=Worksheets("Maths").Range("A2:Z10")
Worksheets("Pattern").Range("A3:Z10").Copy Destination:=Worksheets("English").Range("A2:Z10")
    
End Sub


</PRE>
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Code:
Sub switchS(Optional sWSName As String)
    'Note this macro needs to be run from the original sheet
    'or needs to be called with the name of the original sheet
    'example: switchS MySheet1
    
    Dim coChrt As ChartObject
    Dim sCrtRng As String, sForm As String
    Dim wsWS As Worksheet, i As Integer
    
    If sWSName = vbNullString Then
        sWSName = ActiveSheet.Name
    End If
    
    For Each wsWS In Worksheets
 '       wsWS.Select
        For Each coChrt In wsWS.ChartObjects
            With coChrt.Chart
                For i = 1 To .SeriesCollection.Count
                    sForm = .SeriesCollection(i).Formula
                    sCrtRng = Replace(sForm, sWSName, wsWS.Name)
                    .SeriesCollection(i).Formula = sCrtRng
                Next
            End With
        Next coChrt
    Next wsWS
End Sub
 
Upvote 0

Forum statistics

Threads
1,207,261
Messages
6,077,364
Members
446,280
Latest member
Danielosama

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