PC Review


Reply
Thread Tools Rate Thread

Copy embedded chart with updated data request

 
 
joecrabtree
Guest
Posts: n/a
 
      5th Dec 2007
To all,

I have an embedded chart in worksheet 'test' in workbook testmacro.xls

I want the user to click on the chart, which will then copy the chart
(not as a picture) to a seperate workbook entitled testmacro2.xls into
worksheet 'test2' at range "B2".

How can I then make it so that any changes in the orginal embedded
chart in 'test' i.e. change in data range etc, are reflected in the
copied chart in testmacro2.xls?

Any help you could give me on this would be appreciated.

Regards

Joseph Crabtree
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      5th Dec 2007
Hi Joseph,

Right click your chart, Assign Macro...

Sub CopyMe()
Dim sBook As String, sSheet As String
Dim ans As Long
Dim ws As Worksheet
Dim wb As Workbook
Dim chtObj As ChartObject
Dim obj

sBook = "Book2" ' in my testing
'sBook = "testmacro.xls" ' uncomment
sSheet = "test2"

On Error Resume Next
Set obj = ActiveSheet.ChartObjects(Application.Caller)
If TypeName(obj) = "ChartObject" Then
Set wb = Workbooks("Book2")
If wb Is Nothing Then
MsgBox "the workbook " & sBook & " is not available"
Else
Set ws = wb.Worksheets(sSheet)

If ws Is Nothing Then
Set ws = wb.Worksheets.Add
ws.Name = "test2"
End If
wb.Activate
ws.Activate
For Each chtObj In ws.ChartObjects
If chtObj.TopLeftCell.Address = "$B$2" Then
ans = MsgBox("Delete exisiting chart", vbYesNoCancel)
If ans = vbYes Then
chtObj.Delete
ElseIf ans = vbCancel Then Exit Sub
End If
Exit For
End If
Next

ws.Range("B2").Select
obj.Chart.ChartArea.Copy
ActiveSheet.Paste
ws.Range("A1").Select

End If
End If

End Sub

Regards,
Peter T

"joecrabtree" <(E-Mail Removed)> wrote in message
news:fdf0b4d3-b217-4769-8e7c-(E-Mail Removed)...
> To all,
>
> I have an embedded chart in worksheet 'test' in workbook testmacro.xls
>
> I want the user to click on the chart, which will then copy the chart
> (not as a picture) to a seperate workbook entitled testmacro2.xls into
> worksheet 'test2' at range "B2".
>
> How can I then make it so that any changes in the orginal embedded
> chart in 'test' i.e. change in data range etc, are reflected in the
> copied chart in testmacro2.xls?
>
> Any help you could give me on this would be appreciated.
>
> Regards
>
> Joseph Crabtree



 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      5th Dec 2007
Typo -

change

> Set wb = Workbooks("Book2")


to
Set wb = Workbooks(sBook)

Peter T

"Peter T" <peter_t@discussions> wrote in message
news:(E-Mail Removed)...
> Hi Joseph,
>
> Right click your chart, Assign Macro...
>
> Sub CopyMe()
> Dim sBook As String, sSheet As String
> Dim ans As Long
> Dim ws As Worksheet
> Dim wb As Workbook
> Dim chtObj As ChartObject
> Dim obj
>
> sBook = "Book2" ' in my testing
> 'sBook = "testmacro.xls" ' uncomment
> sSheet = "test2"
>
> On Error Resume Next
> Set obj = ActiveSheet.ChartObjects(Application.Caller)
> If TypeName(obj) = "ChartObject" Then
> Set wb = Workbooks("Book2")
> If wb Is Nothing Then
> MsgBox "the workbook " & sBook & " is not available"
> Else
> Set ws = wb.Worksheets(sSheet)
>
> If ws Is Nothing Then
> Set ws = wb.Worksheets.Add
> ws.Name = "test2"
> End If
> wb.Activate
> ws.Activate
> For Each chtObj In ws.ChartObjects
> If chtObj.TopLeftCell.Address = "$B$2" Then
> ans = MsgBox("Delete exisiting chart", vbYesNoCancel)
> If ans = vbYes Then
> chtObj.Delete
> ElseIf ans = vbCancel Then Exit Sub
> End If
> Exit For
> End If
> Next
>
> ws.Range("B2").Select
> obj.Chart.ChartArea.Copy
> ActiveSheet.Paste
> ws.Range("A1").Select
>
> End If
> End If
>
> End Sub
>
> Regards,
> Peter T
>
> "joecrabtree" <(E-Mail Removed)> wrote in message
> news:fdf0b4d3-b217-4769-8e7c-(E-Mail Removed)...
> > To all,
> >
> > I have an embedded chart in worksheet 'test' in workbook testmacro.xls
> >
> > I want the user to click on the chart, which will then copy the chart
> > (not as a picture) to a seperate workbook entitled testmacro2.xls into
> > worksheet 'test2' at range "B2".
> >
> > How can I then make it so that any changes in the orginal embedded
> > chart in 'test' i.e. change in data range etc, are reflected in the
> > copied chart in testmacro2.xls?
> >
> > Any help you could give me on this would be appreciated.
> >
> > Regards
> >
> > Joseph Crabtree

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't copy workseet with embedded chart JGeniti Microsoft Excel Programming 0 7th Dec 2005 07:02 PM
Removing data from an automatically updated chart =?Utf-8?B?UmVhbGx5ZHVtYg==?= Microsoft Excel Charting 0 16th Aug 2005 01:57 AM
What if I DON'T want the chart to be updated when source data changes? arhooley Microsoft Excel Charting 2 9th Jun 2005 05:07 AM
How do I request updated personal details of people in Access data =?Utf-8?B?RElUUg==?= Microsoft Access Queries 1 21st Apr 2005 05:34 AM
delegate accepts updated meeting request => not updated in managers calendar =?Utf-8?B?Q29ubnkgUHV0?= Microsoft Outlook Calendar 2 9th Feb 2004 11:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:19 AM.