Hello,
I would like to create a graph from a macro. Here is what I have got so far.
Charts.Add
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=Sheets(sheetname).Range("AF1:" & lastcell2, "BN1:" & lastcell), PlotBy:=xlColumns ****<------ something is wrong here
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Pressures"
Sheets(1).Move after:=Sheets(2)
ActiveChart.SeriesCollection(1).XValues = Sheets(sheetname).Range(("AL2"), lastcell3)
ActiveChart.SeriesCollection(2).XValues = Sheets(sheetname).Range(("AL2"), lastcell3)
ActiveChart.SeriesCollection(3).XValues = Sheets(sheetname).Range(("AL2"), lastcell3)
ActiveChart.SeriesCollection(4).XValues = Sheets(sheetname).Range(("AL2"), lastcell3)
ActiveChart.SeriesCollection(5).XValues = Sheets(sheetname).Range(("AL2"), lastcell3)
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Pressure During Test"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Hours"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Pressure (psi)"
End With
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlBottom
I am managining wth the rest of this stuff but I marked a line of code with a ***. This line is giving me trouble. I only want to graph the data in column AF-AH and in BN and BO. But it seems to be selecting all the columns in between also.
What is the correct syntax to do this?
One more question, is there a way to get the x axis to be the data in column AL without it being part of the original selection and hwo do I just right the xvalues line only once instead of for each and every column of data?
Configuration: Windows XP Firefox 3.0.3
I agree that knowing the various variable types will help, but without knowing that and assuming that they are "STRING", that part of the code worked for me. What failed was when assigning the XValues.
|
I'm sorry here is the code of a working graphing subroutine, not the one I am trying to get to work.
|