I (a relative newcomer to VBA) am writing an application to automate the
processing and graphical presentation of data. There are six graphs on three
chart sheets and a number of the charts have a couple of schematic diagrams
included to clarify points to the user/client. Below is a section of the code,
which was mostly obtained from the macro recorder. Basically, I have three
schematic diagrams stored on worksheets(1). These each have a specific name
(determined by Excel) - Group 67, Group 68 and Group 69. Dependent upon the
magnitude of an input variable (gs) the appropriate schematic is selected,
copied
and pasted onto one of the charts and then moved into position. This works
fine - first time round. The intention was to permit the user to run the
routine
any number of times by simply selecting the pasted schematic, deleting it
and then running the copy/paste procedure as described again. Unfortunately,
the schematic (which consists of a number of shapes and lines grouped together)
does not retain the same name after being pasted into the chart, and appears
to be assigned a different name every time it is pasted. So my question - how
can I label or name or identify the schematic so that I can delete it? Or
does anyone have any other suggestions as to how to approach this problem?
gs = Val(Worksheets(1).Cells(4, 19))
If gs = 0 Then gp = 67
If gs > 0 Then gp = 68
If gs < 0 Then gp = 69
gpname = "Group " & gp
Worksheets(1).Activate
ActiveSheet.Shapes(gpname).Select
Selection.Copy
Sheets("ChartSheet").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.Paste
Selection.ShapeRange.IncrementLeft 467.24
Selection.ShapeRange.IncrementTop 246#