Advertisement

05.16.2008 at 01:17AM PDT, ID: 23407614
[x]
Attachment Details

Generating multiple charts in one Excel sheet gives compilation error?

Asked by cleany in Active Server Pages (ASP), Microsoft Excel Spreadsheet Software

Tags: Visual Basic

I want to generate more than 1 chart on an Excel sheet.
I managed to make this work for 1 chart per sheet with a different code and found this code for multiple charts.

The problem is, that I get a compilation error on line 19. It says: compilation error: Expected statement.
line19 is:
MyExcelChart.ActiveChart.SetSourceData Source:=MyExcelChart.Sheets("Sheet1").Range(MyRange), PlotBy:=xlColumns

anyone knows how to solve this?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
'Make the object, and set the object to an Excelsheet
Dim MyExcelChart, MyRange
 
Set MyExcelChart = wscript.CreateObject("Excel.Sheet")
b = MyExcelChart.ActiveSheet.Shapes.Count ' if there are other Shapes in ActiveSheet
' show or dont show excel to user, TRUE or FALSE
MyExcelChart.Application.Visible = True
 
For a = 1 To 3
   MyRange = MyExcelChart.ActiveSheet.Range(MyExcelChart.Sheets("Sheet1").Cells(a * 10 - 9, 1), MyExcelChart.Sheets("Sheet1").Cells(a * 10 - 5, 2)).Address(0, 0)
 ' Select the contents that need to be in the chart
   'MyExcelChart.ActiveSheet.Range(MyExcelChart.Sheets("Sheet1").Cells(a * 10 - 9, 1), MyExcelChart.Sheets("Sheet1").Cells(a * 10 - 5, 2)).Select
 
   MyExcelChart.Charts.Add
   MyExcelChart.ActiveChart.ChartType = 20
   MyExcelChart.ActiveChart.BarShape =3
   MyExcelChart.ActiveChart.HasTitle = True
   MyExcelChart.ActiveChart.ChartTitle.Text = "ok"
   MyExcelChart.ActiveChart.SetSourceData Source:=MyExcelChart.Sheets("Sheet1").Range(MyRange), PlotBy:=xlColumns
 
   MyExcelChart.ActiveChart.Location 1
   MyExcelChart.ActiveSheet.Shapes(a + b).Name = "MyChart" & a
 
   With MyExcelChart.ActiveSheet.Shapes("MyChart" & a)
      .Top = MyExcelChart.Sheets("Sheet1").Range(MyRange).Top
      .Height = MyExcelChart.Sheets("Sheet1").Range(MyRange).Height * 1.9
      .Width = MyExcelChart.Sheets("Sheet1").Range(MyRange).Width * 1.9
   End With
   MyExcelChart.ActiveChart.HasDataTable = False
   MyExcelChart.ActiveChart.DataTable.ShowLegendKey = False
Next
 
' Save the the excelsheet to chart.xls
MyExcelChart.SaveAs "c:\export.xls"
 
Loading Advertisement...
 
[+][-]05.16.2008 at 03:32AM PDT, ID: 21581524

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 09:12AM PDT, ID: 21584049

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 09:19AM PDT, ID: 21584103

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Active Server Pages (ASP), Microsoft Excel Spreadsheet Software
Tags: Visual Basic
Sign Up Now!
Solution Provided By: rorya
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628