Serving the Quantitative Finance Community

 
User avatar
InMyWoodenHut
Topic Author
Posts: 0
Joined: November 14th, 2003, 3:34 pm

VBA : create graph from a Variant

November 9th, 2004, 5:37 pm

Hi, I have a variant named "My_Matrix" with 5 columns and n lines, I would like to create a graphe with it, what would be the " .SetSourceData Source:=" statement for that ? Thanx for your help,
 
User avatar
spursfan
Posts: 2
Joined: October 7th, 2001, 3:43 pm

VBA : create graph from a Variant

November 10th, 2004, 4:29 pm

if the matrix is a range on a spreadsheet the easiest way is to use the macro recorder whilst using the chart wizard and see what the resulting code looks like: otherwise you could return the VBA variant to the spreadsheet and then use the macro recorder
 
User avatar
Doney
Posts: 0
Joined: June 24th, 2004, 7:14 am

VBA : create graph from a Variant

November 11th, 2004, 11:01 am

If you're doing this dynamically (ie without a range), you'd have to build a helper function for this. To assign values to a Series, you can use Series.Values = "={val1,val2,val3}". Since you've got 5 columns, you'd have n vals in each series, and 5 series, so if you wanted to use this method, you'd have to build a string for this formula...
 
User avatar
InMyWoodenHut
Topic Author
Posts: 0
Joined: November 14th, 2003, 3:34 pm

VBA : create graph from a Variant

November 12th, 2004, 6:19 am

thank you guys. Actually I found a macro that does this : the only problem is that the number of values that can be taken is limited. '#########################################################' First place the data in two columns and select the corresponding rangeSub Graphwithoutlink()Application.ScreenUpdating = FalseSet donne = Selectionnom = ActiveSheet.NameCharts.AddWith ActiveChart .ChartType =xlXYScatterLines .SetSourceData Source:=donne .Location Where:=xlLocationAsObject, Name:=nomEnd WithWith ActiveChart.SeriesCollection(1) .XValues= donne.Columns(1).Cells().Value .Values = donne.Columns(2).Cells().ValueEnd WithActiveChart.HasLegend = Falsedonne.Cells(1, 1).Selectdernier =ActiveSheet.ChartObjects.CountWith ActiveSheet.ChartObjects(dernier) .Top = ActiveCell.Offset(0, 2).Top .Left = ActiveCell.Offset(0, 2).LeftEndWithEnd Sub