How to create chart using VB 6.0

T

Tomasz Klim

Hi

I try to create a simple line-chart from external program in Visual Basic
6.0. I already generate a quite complex Excel sheet without problems, but
when I try to add chart into this sheet, I don't see anything.

Can you check my code in case of errors? In general, when I created this
code, I followed Macro Recorder and existing code (dynamic series updating
on existing chart).


oExcel.GetWorkbook.Sheets("Main_Wykres").Charts.Add
With oExcel.GetExcel.ActiveChart
.ChartType = xlLine
.SetSourceData
Source:=oExcel.GetWorkbook.Sheets("Main_Macierz").Range("B2:AK16"),
PlotBy:=xlRows
.SeriesCollection(1).Name = Cells(2, 1)
.SeriesCollection(1).XValues = Range("B1:AK1")

For intSeria = 2 To 16
.SeriesCollection.NewSeries.Name = Cells(intSeria, 1)
.SeriesCollection.NewSeries.XValues = Range("B1", "AK1")
.SeriesCollection.NewSeries.Values = Range("B" & intSeria &
":AK" & intSeria)
Next

.Location Where:=xlLocationAsNewSheet
'.Location Where:=xlLocationAsObject, Name:="Main_Wykres"
.HasTitle = True
.ChartTitle.Text = "Multi Trend"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False

.Refresh
End With
 
G

Guest

G

Guest

yes thankx. but my problem is that i just dont know how to refer to cell
"dynamically". e.g. in the example you refered to they write:

Source:=Sheets("Sheet1").Range("C3").CurrentRegion

what i want to know is how you refer to a cell in antother way than Range.
since my cell is variable I want to refer to it in a way so that i can write
(this is not really code im just saying what i want to do..)

(x,y) = rng.Address -----i.e. get the adress from a cell and store it in x
and y. x for rows and y columns or vice versa.
then i want to e.g. add 3 to rows i want to write: x=x+3
making the chart then is easy if you can refer to it as Range(x,y). There is
a function Cells or something but i really dont know how to fix it.
desperatly needs help. !!!!




"Tom Ogilvy" skrev:
 
G

Guest

assuming rng is a reference to a single cell, for illustration, assume C3

rng.resize(3,1) ' C3:C5

rng.offset(1,0) ' C4

rng.offset(1,0).Resize(3,1) 'C4:C6
 

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

Similar Threads

Creating Charts using VBA 0
controlling chart location 1
Changing Input to code that creates a chart 2
Delete a chart 4
Deleting Charts 4
Showing charts with hidden data 4
Chart VBA 2
Chart error 2

Top