PDA

View Full Version : Solved: Chart using VBA



nitzbar
09-04-2008, 10:44 AM
Am trying to get VBA to chart the output from another procedure.Am looking at a scatter chart with 2 series, column j values on the x axis and columns k and l values on the y axis.
Here is what i have got do far.

Sub AddChart()
Dim chtChart As Chart

ActiveSheet.ChartObjects.Delete
'Create a new chart.
Set chtChart = Charts.Add
Set chtChart = chtChart.Location(Where:=xlLocationAsObject, Name:="Trades")
With chtChart
.ChartType = xlXYScatter
'Set data source range.
.SetSourceData Source:=Sheets("Trades").Range("j1:l1000"), PlotBy:=xlColumns
.HasTitle = True
.ChartTitle.Text = "Point and Figure"
'The Parent property is used to set properties of the Chart.
With .Parent
.Top = Range("F9").Top
.Left = Range("F9").Left
.Name = "Point and Figure Chart"
End With
End With
End Sub


Also, I would like to customize the chart in the following ways.

1. Have custom markers (shape, color) and marker sizes for both series
2. Adjust range of both axes
3. Add axes names
4 Also, is it possible to have an open ended data range ? I am using values that are continuously streaming in , so might have more than 32000 values ( Doubtful, but would like to know)

Would really appreciate it if someone could help me out.

Thanks.

SQChevy
09-08-2008, 02:00 PM
One of the easiest ways to set it to do exactly what you want it to record a macro of you changing those settings to the shape and color you like. This will provide the code you need to put into your code. As far as open ended data range, my suggestion would be to set a variable that will be run before the chart is made to go down every row until it gets no data. Then use that with ranges to tell excel what to use. Let me know if you need some help with that part of the code and I will show what I used.

nitzbar
09-11-2008, 10:21 AM
Thanks... I got this one figured out.