jk2880


I am using a macro to create multiple charts from data on a separate sheet in the Excel file. However, the program places each new chart on top of the previous one in the sheet I select. I would like to place these charts apart on the sheet so that they are viewable.

1) Is there an command to order the charts down and across the sheet
2) Alternatively, can I select and move each sheet without using the actual object name in the while loop, "Chart1," for example.
3) Specifiying the object name would only work for the first chart. Is there a way to number the charts with a variable

Here is the while portion of my code as it is now (red text indicates the portion I am having difficulty with):

While j < 243

Charts.Add

With Sheets("TRESULTSdmp_3")
ActiveChart.SetSourceData Source:=.Range(.Cells(i + 1, j + 1), .Cells(i + m, j + 1)), PlotBy:=xlColumns
End With

ActiveChart.ChartType = xlXYScatter
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Test point to the right"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With

ActiveWindow.Visible = False <----- question 2 above) want to move object to a specific location
ActiveWindow.WindowState = xlNormal (will have to make Range a variable)
ActiveWindow.WindowState = xlMaximized
Range("A1").Select
ActiveSheet.ChartObjects("Chart 8").Activate
ActiveChart.Paste

ActiveSheet.Shapes("Chart 3").IncrementLeft -123.75 <--- question 3 above) want to make object # variable
ActiveSheet.Shapes("Chart 3").IncrementTop -8.25

j = j + 1

Wend


Re: VBA in Excel - organizing charts as objects in a sheet

bi-lya


See the example

Code Snippet

'First SourceData Range is "A1:B5"
'Second SourceData Range is "A11:B25"
'Third SourceData Range is "A21:B45"


b = ActiveSheet.Shapes.Count ' if there are other Shapes in ActiveSheet


For a = 1 To 3
MyRange = Range(Sheets("Sheet1").Cells(a * 10 - 9, 1), _
Sheets("Sheet1").Cells(a * 10 - 5, 2)).Address(0, 0)
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range(MyRange), PlotBy:= _
xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"


ActiveSheet.Shapes(a + b).Name = "MyChart" & a


With ActiveSheet.Shapes("MyChart" & a)
.Top = Sheets("Sheet1").Range(MyRange).Top
.Height = Sheets("Sheet1").Range(MyRange).Height * 1.9
.Width = Sheets("Sheet1").Range(MyRange).Width * 1.9
End With
Next

You may not name a Chart/Shape if you will not use it at a later time