ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   define chart series from single column (https://www.excelbanter.com/excel-discussion-misc-queries/143756-define-chart-series-single-column.html)

Maarten

define chart series from single column
 
Hi list,
is there any way to define different series for a scatterplot from a single
column?
I have data organised in three columns: column 1 and 2 contain the X and Y
coordinates and column 3 contains the codes (to define the series).
X Y code
-0,25586 -1,41622 A
0,00779 -1,27963 A
0,80316 -0,56037 A
0,72824 0,40388 A
0,89184 0,53479 A
-0,44546 -0,11075 B
-0,28927 -0,16976 B
-0,02147 0,18616 B
0,01244 0,63664 B
0,01123 0,66995 B

Normally you put the series next to each other, but that is very time
consuming if you have a lot of series. It would be easier if Excel could
recognize the labels in column 3 as separate series.

Maarten


joel

define chart series from single column
 
Her is some code that will help. On sheet1 put the x,y,code in columns a - c
starting at row 1. then run macro.



Sub Scatterplot()


First = True
Endrow = Cells(Rows.Count, "A").End(xlUp).Row
RowCount = 1
Do While RowCount <= Endrow

Firstrow = RowCount
Sheets("sheet1").Cells(RowCount, 1).Activate
Do While Cells(RowCount, "C") = Cells(RowCount + 1, "C")
RowCount = RowCount + 1
Loop
Lastrow = RowCount

If First = True Then

Set ChartRange = Sheets("Sheet1").Range("A" & CStr(Firstrow) & ":B" &
CStr(Lastrow))
Charts.Add
newchartname = "Chart " & CStr(Mid(ActiveChart.Name, 6))
ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=ChartRange
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
newchartname = Mid(ActiveChart.Name, 6)
newchartname = Mid(newchartname, InStr(newchartname, "Chart"))
First = False
Else

Worksheets("sheet1").ChartObjects(newchartname).Ac tivate
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).XValues = _
"=Sheet1!R" & CStr(Firstrow) & "C1:R" & CStr(Lastrow) & "C1"
ActiveChart.SeriesCollection(2).Values = _
"=Sheet1!R" & CStr(Firstrow) & "C2:R" & CStr(Lastrow) & "C2"
End If

RowCount = RowCount + 1
Loop
End Sub

"Maarten" wrote:

Hi list,
is there any way to define different series for a scatterplot from a single
column?
I have data organised in three columns: column 1 and 2 contain the X and Y
coordinates and column 3 contains the codes (to define the series).
X Y code
-0,25586 -1,41622 A
0,00779 -1,27963 A
0,80316 -0,56037 A
0,72824 0,40388 A
0,89184 0,53479 A
-0,44546 -0,11075 B
-0,28927 -0,16976 B
-0,02147 0,18616 B
0,01244 0,63664 B
0,01123 0,66995 B

Normally you put the series next to each other, but that is very time
consuming if you have a lot of series. It would be easier if Excel could
recognize the labels in column 3 as separate series.

Maarten


Maarten

define chart series from single column
 
Works great! Thanks!

"Joel" wrote:

Her is some code that will help. On sheet1 put the x,y,code in columns a - c
starting at row 1. then run macro.



Sub Scatterplot()


First = True
Endrow = Cells(Rows.Count, "A").End(xlUp).Row
RowCount = 1
Do While RowCount <= Endrow

Firstrow = RowCount
Sheets("sheet1").Cells(RowCount, 1).Activate
Do While Cells(RowCount, "C") = Cells(RowCount + 1, "C")
RowCount = RowCount + 1
Loop
Lastrow = RowCount

If First = True Then

Set ChartRange = Sheets("Sheet1").Range("A" & CStr(Firstrow) & ":B" &
CStr(Lastrow))
Charts.Add
newchartname = "Chart " & CStr(Mid(ActiveChart.Name, 6))
ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=ChartRange
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
newchartname = Mid(ActiveChart.Name, 6)
newchartname = Mid(newchartname, InStr(newchartname, "Chart"))
First = False
Else

Worksheets("sheet1").ChartObjects(newchartname).Ac tivate
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).XValues = _
"=Sheet1!R" & CStr(Firstrow) & "C1:R" & CStr(Lastrow) & "C1"
ActiveChart.SeriesCollection(2).Values = _
"=Sheet1!R" & CStr(Firstrow) & "C2:R" & CStr(Lastrow) & "C2"
End If

RowCount = RowCount + 1
Loop
End Sub

"Maarten" wrote:

Hi list,
is there any way to define different series for a scatterplot from a single
column?
I have data organised in three columns: column 1 and 2 contain the X and Y
coordinates and column 3 contains the codes (to define the series).
X Y code
-0,25586 -1,41622 A
0,00779 -1,27963 A
0,80316 -0,56037 A
0,72824 0,40388 A
0,89184 0,53479 A
-0,44546 -0,11075 B
-0,28927 -0,16976 B
-0,02147 0,18616 B
0,01244 0,63664 B
0,01123 0,66995 B

Normally you put the series next to each other, but that is very time
consuming if you have a lot of series. It would be easier if Excel could
recognize the labels in column 3 as separate series.

Maarten



All times are GMT +1. The time now is 04:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com