pugap
Mechanical
- Nov 18, 2003
- 45
Working on a spreadsheet that imports data from text files, based on user input. For each set of data, a new sheet is created and the data is put on that sheet. An input box allows the user to name the sheet as the data is being input. All this works ok. I've also got a routine that puts the sheet names into an array (i.e. SheetName(15)). All of the data has the same format and same number of rows.
Now the part that's not working. I want to be able to plot the data on an xyscatter chart. Since I won't know how many sheets are read in ahead of time, I first count the number of sheets (SheetCount). Then I loop through the sheets, and try to get the X & Y data. I assign the ranges to a stringname (XRange, YRange).
The code looks something like this:
SheetCount = ThisWorkbook.Sheets.Count
Charts.Add
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
For intLoop = 1 To SheetCount
xRange = "=" & SheetName(intLoop) & "!R2C2:R467C2"
yRange = "=" & SheetName(intLoop) & "!R2C1:R467C1"
ActiveChart.SeriesCollection.NewSeries
******THE NEXT LINE IS WHERE IT HANGS UP*********
ActiveChart.SeriesCollection(intLoop).xValues = xRange
ActiveChart.SeriesCollection(intLoop).Values = yRange
Next intLoop
The error message is "Unable to set the XValues property of the series class". I'm not sure why, because it is looking at the right sheet name when it runs through the loop. Any ideas on what to look for? Thanks in advance.
Now the part that's not working. I want to be able to plot the data on an xyscatter chart. Since I won't know how many sheets are read in ahead of time, I first count the number of sheets (SheetCount). Then I loop through the sheets, and try to get the X & Y data. I assign the ranges to a stringname (XRange, YRange).
The code looks something like this:
SheetCount = ThisWorkbook.Sheets.Count
Charts.Add
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
For intLoop = 1 To SheetCount
xRange = "=" & SheetName(intLoop) & "!R2C2:R467C2"
yRange = "=" & SheetName(intLoop) & "!R2C1:R467C1"
ActiveChart.SeriesCollection.NewSeries
******THE NEXT LINE IS WHERE IT HANGS UP*********
ActiveChart.SeriesCollection(intLoop).xValues = xRange
ActiveChart.SeriesCollection(intLoop).Values = yRange
Next intLoop
The error message is "Unable to set the XValues property of the series class". I'm not sure why, because it is looking at the right sheet name when it runs through the loop. Any ideas on what to look for? Thanks in advance.