Problem placing embedded charts

C

Chris A

A simple problem that hopefully someone can help me with:

I am trying to write a macro that will create several charts from data on
one sheet and place the charts into another sheet. I have two problems:

1. When creating the charts, passing various width parameters is producing
strange results. Namely, I create the first chart in one sub with something
that looks like this:

Sheets(“Sheet1â€).ChartObjects.Add Left:=200, Top:=50, Width:=400, Height:=250
‘ [code setting all the chart parameters…seems to be working fine]
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet3"

Next, I want to create another chart with the same dimensions as the one
above but with different data. I would have expected that I could use the
same Width and Height parameters to ChartObjects.Add as above, but through
trial and error I have found I need to use the following:

Sheets(“Sheet1â€).ChartObjects.Add Left:=620, Top:=50, Width:=150, Height:=250
‘ [code setting all the chart parameters…seems to be working fine]
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet3"

This creates two charts side by side with about the same dimensions. The
question, then, is why the two different width parameters create the same
approximate result.

2. Even when using these parameters determined through trial and error, I
get unexpected results. When I run the two procedures independently or
together they produce output as expected. When, however, I run them followed
by two more procedures that essentially do the same thing, but with different
data and with the resulting charts going to a different sheet, the two charts
created using the code above wind up directly on top of each other, and the
two charts created with otherwise identical code wind up swapping places
(i.e. the chart with the left parameter of 620 winds up on the left of the
chart with the left parameter of 200).

I know I’m doing something wrong, but I don’t know what. Any help would be
appreciated.

One final question: How do I zoom the viewable area so that, once created
and placed into the right position, the charts are fully visible, regardless
of how the user has the zoom set prior to macro execution?

Thanks

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top