M
MikeZz
Hi,
I have a very complex chart with about 400 lines on X-Y chart.
The issue is that not all the series have the same range as the "XValue" so
if I autofilter the data, it hides the Xvalue range on some series and so it
doesn't scale hte X-Axis correctly.
Because if this, I want to search through all the series where the data
comes from a worksheet with "data" in the name. Find the series that has the
"xValue" row at the top of the page and then set all the other data series
X-Values to the one at the top of the row.
Not all series point to the same data worksheet and there could be other
issues (I didn't build the chart).
Any help would be great!
Dim rngDataSource As Range
Dim iDataRowsCt As Long
Dim iDataColsCt As Integer
Dim iSrsIx As Integer
Dim chtChart As Chart
Dim srsNew As Series
Dim rngXVal As Range
Dim addXVals
Dim dataSheetName
Dim topXval
Dim thisXvalRow
Dim sCount
dataSheetName = "data"
topXval = 1000
Application.ScreenUpdating = False
Set cht = ActiveChart
If cht.ChartType = 0 Then Exit Sub
For Each srs In cht.SeriesCollection
addXVals = Extract_Series_Ranges(srs.FormulaR1C1, "X")
If InStr(1, srs.Name, "ARC") = 0 And InStr(1, srs.Name, "RIM") =
0 Then
If InStr(1, addXVals, dataSheetName) > 0 Then
thisXvalRow = Range(addXVals).Row
If thisXvalRow < topXval Then
topXval = thisXvalRow
End If
End If
End If
Next
Application.ScreenUpdating = True
End Sub
Private Function Extract_Series_Ranges(SerForm, XorY)
Dim comma1, comma2, comma3, comma4
Dim xRange
Dim yRange
Dim nRange
Dim par1
Dim Ord
par1 = InStr(1, SerForm, "(")
comma1 = InStr(1, SerForm, ",")
comma2 = InStr(comma1 + 1, SerForm, ",")
comma3 = InStr(comma2 + 1, SerForm, ",")
comma4 = InStr(comma3 + 1, SerForm, ",")
nRange = Mid(SerForm, par1 + 1, comma1 - par1 - 1)
xRange = Mid(SerForm, comma1 + 1, comma2 - comma1 - 1)
yRange = Mid(SerForm, comma2 + 1, comma3 - comma2 - 1)
Ord = Mid(SerForm, comma3 + 1, Len(SerForm) - comma3 - 1)
Select Case XorY
Case "X"
Extract_Series_Ranges = xRange
Case "Y"
Extract_Series_Ranges = yRange
Case "Name"
Extract_Series_Ranges = nRange
Case "Ord"
Extract_Series_Ranges = Ord
End Select
End Function
I have a very complex chart with about 400 lines on X-Y chart.
The issue is that not all the series have the same range as the "XValue" so
if I autofilter the data, it hides the Xvalue range on some series and so it
doesn't scale hte X-Axis correctly.
Because if this, I want to search through all the series where the data
comes from a worksheet with "data" in the name. Find the series that has the
"xValue" row at the top of the page and then set all the other data series
X-Values to the one at the top of the row.
Not all series point to the same data worksheet and there could be other
issues (I didn't build the chart).
Any help would be great!
Dim rngDataSource As Range
Dim iDataRowsCt As Long
Dim iDataColsCt As Integer
Dim iSrsIx As Integer
Dim chtChart As Chart
Dim srsNew As Series
Dim rngXVal As Range
Dim addXVals
Dim dataSheetName
Dim topXval
Dim thisXvalRow
Dim sCount
dataSheetName = "data"
topXval = 1000
Application.ScreenUpdating = False
Set cht = ActiveChart
If cht.ChartType = 0 Then Exit Sub
For Each srs In cht.SeriesCollection
addXVals = Extract_Series_Ranges(srs.FormulaR1C1, "X")
If InStr(1, srs.Name, "ARC") = 0 And InStr(1, srs.Name, "RIM") =
0 Then
If InStr(1, addXVals, dataSheetName) > 0 Then
thisXvalRow = Range(addXVals).Row
If thisXvalRow < topXval Then
topXval = thisXvalRow
End If
End If
End If
Next
Application.ScreenUpdating = True
End Sub
Private Function Extract_Series_Ranges(SerForm, XorY)
Dim comma1, comma2, comma3, comma4
Dim xRange
Dim yRange
Dim nRange
Dim par1
Dim Ord
par1 = InStr(1, SerForm, "(")
comma1 = InStr(1, SerForm, ",")
comma2 = InStr(comma1 + 1, SerForm, ",")
comma3 = InStr(comma2 + 1, SerForm, ",")
comma4 = InStr(comma3 + 1, SerForm, ",")
nRange = Mid(SerForm, par1 + 1, comma1 - par1 - 1)
xRange = Mid(SerForm, comma1 + 1, comma2 - comma1 - 1)
yRange = Mid(SerForm, comma2 + 1, comma3 - comma2 - 1)
Ord = Mid(SerForm, comma3 + 1, Len(SerForm) - comma3 - 1)
Select Case XorY
Case "X"
Extract_Series_Ranges = xRange
Case "Y"
Extract_Series_Ranges = yRange
Case "Name"
Extract_Series_Ranges = nRange
Case "Ord"
Extract_Series_Ranges = Ord
End Select
End Function