Bill,
thanks for your suggestion, and sorry for the chaotic
layout of my code. I've tried your code (thanks for the
replace, that's much better than my version), and I
modified it slightly because I couldn't make the Chart
Objects work otherwise (see below). However, it comes up
with the same faulty result as my code does.
Actually, by single-stepping my original code, I found
that the error happens quite early: when the program is
supposed to grab the formula of the last series of a
chart, it does in fact grab the formula of the first
series. And oddly enough, when writing to the formula of
the last series, it d o e s grab the last series, so in
fact in overwrites the last series with the first series.
And the same happens in your code as well (though not
separated into two steps). I have no idea whether that is
a special issue of my workbook with its special charts
(which I inherited from somebody) or whether that is a bug
or ...
Any further ideas are welcome, although I have by now
solved my application problem by running the code on all
but the last series and modifying the last series manually.
Regards, Ulrike
Code:
Sub makelonger()
Dim lngWorksheetNumber As Long
Dim ws As Worksheet
Dim objChart As Chart
Dim objSeries As Series
For lngWorksheetNumber = 12 To 19
Set ws = Worksheets(lngWorksheetNumber)
anz = ws.ChartObjects.Count
For i = 1 To anz
Set objChart = ws.ChartObjects(i).Chart
For Each objSeries In objChart.SeriesCollection
'Don't know what this unneeded code is; must be
global variable.
On Error GoTo naechste
With objSeries
.Formula = Replace(Expression:=.Formula, _
Find:="$Z", _
Replace:="$AD", _
Compare:=vbTextCompare)
End With
naechste:
Next objSeries
Next i
Next lngWorksheetNumber
End Sub
>-----Original Message-----
>Try this revised (but untested) code. I converted most of
your code over to
>object variables, to make debugging easier. You should be
able to
>single-step through the code and use the Locals window to
verify what the
>objects are actually set to. This will also allow you to
see what properties
>and methods would be useful at each stage of the process.
The Replace
>function should replace each occurence of "$Z" in your
series formulas and
>should be a much easier way to do it. Your code line-
wrapped pretty bad in
>your post, but I think I got it okay.
>
>Sub makelonger()
> Dim lngWorksheetNumber As Long
> Dim ws As Worksheet
> Dim objChart As Chart
> Dim objSeries As Series
>
> For lngWorksheetNumber = 12 To 19
> Set ws = Worksheets(lngWorksheetNumber)
>
> For Each objChart In ws.ChartObjects
> For Each objSeries In objChart.SeriesCollection
> 'Don't know what this unneeded code is; must be
global variable.
> titel = objChart.ChartTitle
>
> On Error GoTo naechste
>
> With objSeries
> .Formula = Replace(Expression:=.Formula, _
> Find:="$Z", _
> Replace:="$AD", _
> Compare:=vbTextCompare)
> End With
>naechste:
> Next objSeries
> Next objChart
> Next lngWorksheetNumber
>End Sub
>--
>Regards,
>Bill
>
>
>"Ulrike Grömping" <(E-Mail Removed)>
wrote in message
>news:5ec201c42de4$39ea0d10$(E-Mail Removed)...
>> It is not the third series but the last series of each
>> chart that gets the same data as the first series. But I
>> still don't have a clue why.
>>
>> Regards, Ulrike
>>
>> >-----Original Message-----
>> >Dear all,
>> >
>> >I'm trying to change the formulae in many line charts
by
>> >adding four points
>> >to each chart, i.e. the old range goes through to
>> >column "Z", the new range
>> >is supposed to go through to column "AD".
>> >
>> >Whenever I do this, the third series gets the data from
>> >the first series
>> >(subsequent series are ok again), and I have no clue,
why
>> >that might be the
>> >case. Any ideas?
>> >
>> >Regards, Ulrike
>> >
>> >Code:
>> >Sub makelonger()
>> >For i = 12 To 19
>> > For j = 1 To Worksheets(i).ChartObjects.Count
>> > anz = Worksheets(i).ChartObjects
>> >(j).Chart.SeriesCollection.Count
>> > For k = 1 To anz
>> > titel = Worksheets(i).ChartObjects
>> >(j).Chart.Name
>> > On Error GoTo naechste
>> > formel =
>> >Worksheets(i).ChartObjects(j).Chart.SeriesCollection
>> >(k).Formula
>> > formelneu = formel
>> > If InStr(formel, "Z") > 0 Then _
>> > formelneu = Left(formel, InStr
>> >(formel, ":$Z")) & "$AD" & _
>> > Right(formel, Len(formel) - InStr
>> >(formel, "Z"))
>> > If InStr(formelneu, "Z") > 0 Then _
>> > formelneu = Left(formelneu, InStr
>> >(formelneu, ":$Z")) & "$AD"
>> >& _
>> > Right(formelneu, Len(formelneu) - InStr
>> >(formelneu, "Z"))
>> > Worksheets(i).ChartObjects
>> >(j).Chart.SeriesCollection(k).Formula
>> >= formelneu
>> >naechste:
>> > Next k
>> > Next j
>> >Next i
>> >End Sub
>> >
>> >
>> >
>> >.
>> >
>
>
>.
>
|