R
Robert H
I am building charts with non-contiguous ranges. I have struggled
through allot with this but am stumped at getting
SeriesCollection(#).XValues to work correctly. the different syntax I
have tried either gives me an "unable to set the xvalues property of
the series class" error or the results in the source data Catagory X
axis Labels look like :
={"$H$1","$J$1","$L$1","$N$1","$P$1","$R$1","$T$1","$V$1","$X$1"}
with that curved bracket and sometimes extra quotes...
As you can see by the number of .SeriesCollection(1).XValues = xValRng
variations, I have given up any logical approach and am now easter
egging.
Any help will be met with eternal gratitude!
Sub AddChart()
Dim aChart As Chart
Dim shtNm As String
Dim chtLoc1 As Range
Dim srcRng As Range
Dim hdrRow As Range
Dim numRows As Integer
Dim numColumns As Integer
Dim dataTyp As String
Dim c As Range
Dim firstAdd As String
Dim xVal As String
Dim xValRng As Range
dataTyp = "IMP"
shtNm = ActiveSheet.Name
ActiveSheet.ChartObjects.Delete
Set hdrRow = Range(Range("A1"), Selection.End(xlToRight)) '.Select
With hdrRow
Set c = .find(dataTyp, LookIn:=xlValues)
If Not c Is Nothing Then
firstAdd = c.Address
Do
If c.Address = firstAdd Then
xVal = shtNm & "!" & c.Address
Else
xVal = xVal & "," + shtNm & "!" & c.Address
End If
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAdd
End If
End With
shtNm = ActiveSheet.Name
Set chtLoc1 = Range("dc_res")
Set aChart = Charts.Add
Set aChart = aChart.Location(Where:=xlLocationAsObject,
Name:=shtNm)
With aChart
.ChartType = xlLineMarkers
Set srcRng = Union(Sheets(shtNm).Range("CODE"),
Range("IMP_100_Hz"), Range("IMP_200_Hz"), Range("IMP_400_Hz"), _
Range("IMP_1_kHz"), Range("IMP_2_kHz"), Range("IMP_4_kHz"), _
Range("IMP_10_kHz"), Range("IMP_20_kHz"), Range("IMP_40_kHz"))
.SetSourceData Source:=srcRng, _
PlotBy:=xlRows
Debug.Print xVal
Set xValRng = Range(xVal)
xValRng.Select
'.SeriesCollection(1).XValues = .xValRng.Address
'.SeriesCollection(1).XValues = xValRng.Value
'.SeriesCollection(1).XValues = xValRng
'unable to set the xvalues property of the series class
'.SeriesCollection(1).XValues = xVal
'.SeriesCollection(1).XValues =
Worksheets(shtNm).xValRng.Address
'.SeriesCollection(1).XValues =
Worksheets(shtNm).Range(xVal).Address
'.SeriesCollection(1).XValues = Worksheets(shtNm).xVal
.SeriesCollection(1).XValues = xValRng
.HasTitle = True
.ChartTitle.Text = "Configuration " & shtNm & " Impedance"
With .Parent
.Top = chtLoc1.Offset(10, 0).Top
.Left = chtLoc1.Left
.Height = 252
.Width = 432
.Name = shtNm & "ChartDev"
End With
End With
End Sub
through allot with this but am stumped at getting
SeriesCollection(#).XValues to work correctly. the different syntax I
have tried either gives me an "unable to set the xvalues property of
the series class" error or the results in the source data Catagory X
axis Labels look like :
={"$H$1","$J$1","$L$1","$N$1","$P$1","$R$1","$T$1","$V$1","$X$1"}
with that curved bracket and sometimes extra quotes...
As you can see by the number of .SeriesCollection(1).XValues = xValRng
variations, I have given up any logical approach and am now easter
egging.
Any help will be met with eternal gratitude!
Sub AddChart()
Dim aChart As Chart
Dim shtNm As String
Dim chtLoc1 As Range
Dim srcRng As Range
Dim hdrRow As Range
Dim numRows As Integer
Dim numColumns As Integer
Dim dataTyp As String
Dim c As Range
Dim firstAdd As String
Dim xVal As String
Dim xValRng As Range
dataTyp = "IMP"
shtNm = ActiveSheet.Name
ActiveSheet.ChartObjects.Delete
Set hdrRow = Range(Range("A1"), Selection.End(xlToRight)) '.Select
With hdrRow
Set c = .find(dataTyp, LookIn:=xlValues)
If Not c Is Nothing Then
firstAdd = c.Address
Do
If c.Address = firstAdd Then
xVal = shtNm & "!" & c.Address
Else
xVal = xVal & "," + shtNm & "!" & c.Address
End If
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAdd
End If
End With
shtNm = ActiveSheet.Name
Set chtLoc1 = Range("dc_res")
Set aChart = Charts.Add
Set aChart = aChart.Location(Where:=xlLocationAsObject,
Name:=shtNm)
With aChart
.ChartType = xlLineMarkers
Set srcRng = Union(Sheets(shtNm).Range("CODE"),
Range("IMP_100_Hz"), Range("IMP_200_Hz"), Range("IMP_400_Hz"), _
Range("IMP_1_kHz"), Range("IMP_2_kHz"), Range("IMP_4_kHz"), _
Range("IMP_10_kHz"), Range("IMP_20_kHz"), Range("IMP_40_kHz"))
.SetSourceData Source:=srcRng, _
PlotBy:=xlRows
Debug.Print xVal
Set xValRng = Range(xVal)
xValRng.Select
'.SeriesCollection(1).XValues = .xValRng.Address
'.SeriesCollection(1).XValues = xValRng.Value
'.SeriesCollection(1).XValues = xValRng
'unable to set the xvalues property of the series class
'.SeriesCollection(1).XValues = xVal
'.SeriesCollection(1).XValues =
Worksheets(shtNm).xValRng.Address
'.SeriesCollection(1).XValues =
Worksheets(shtNm).Range(xVal).Address
'.SeriesCollection(1).XValues = Worksheets(shtNm).xVal
.SeriesCollection(1).XValues = xValRng
.HasTitle = True
.ChartTitle.Text = "Configuration " & shtNm & " Impedance"
With .Parent
.Top = chtLoc1.Offset(10, 0).Top
.Left = chtLoc1.Left
.Height = 252
.Width = 432
.Name = shtNm & "ChartDev"
End With
End With
End Sub