|
-
Aug 28th, 2003, 12:52 AM
#1
Thread Starter
Hyperactive Member
Excel Graphs and VB
I have a program that creates an Excel spreadsheet and creates a line graph on the spreadsheet. It works great except I need to add another line to the graph. How do I do that? Here is the code I use to create everything:
VB Code:
Dim objExcel As Excel.Application
Dim objWorkBook As Excel.Workbook
Dim objWorkSheet As Excel.Worksheet
Dim objXLRange As Excel.Range
Dim objXLChart As Excel.Chart
Set objExcel = CreateObject("Excel.Application")
Set objWorkBook = objExcel.Workbooks.Add
Set objWorkSheet = objWorkBook.Worksheets(1)
Set objXLRange = objWorkSheet.Range("E2", RangeX)
Set objXLChart = objWorkSheet.Application.Charts.Add
With objXLChart
.ChartType = xlLine
.SetSourceData objXLRange, xlColumns
End With
This is not all the code understand, just enough to let you know how I am doing it all.
-
Aug 28th, 2003, 01:54 AM
#2
Just use the macro-recorder and look what code that generates, copy-adjust-past.
-
Aug 28th, 2003, 02:05 AM
#3
Thread Starter
Hyperactive Member
Because I'm no Excel expert and have no idea of how to do that.
-
Aug 28th, 2003, 02:34 AM
#4
It is quite easy, start the excel macro-recorder (Alt-F8).
Do what you want to do (add the line to the chart) just how you do it normally.
Stop the macro-recorder (it has a stop-button like a cd-player)
Look into the code.
-
Aug 28th, 2003, 03:53 PM
#5
Thread Starter
Hyperactive Member
I don't know why this thread got moved to VBA because I'm not using VBA. I am using VB to do this. Anyway, this is the code I used:
VB Code:
'add another series from your sheet called MySheet
With objXLChart
.ChartArea.Select
i = .SeriesCollection.Count + 1
.SeriesCollection.NewSeries
.SeriesCollection(i).Name = "=Sheet1!R2C6"
.SeriesCollection(i).XValues = "=Sheet1!R2C6:" & RangeY & "C6"
.SeriesCollection(i).Values = "=Sheet1!R2C6:" & RangeY & "C6"
End With
-
Sep 3rd, 2003, 04:47 AM
#6
Hyperactive Member
You may be using VB, but the language used to work in Excel is VBA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|