LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default ChartObjects.Count is incorrect

Thanks for the link! It gave me a couple ideas, but I went in another
direction. I wanted something more simple than what Module could accomplish.

Here's my solution. It could be cleaned up a bit, but it seems to work. At
the moment, there's no validation of movement. You could go outside the
bounds of data, but that's an exercise for another day.

I'm incrementing every chart by 1 row, because that's the structure of my
data/charts. You could change the movement of the chart window as required.

I'm open to any feedback. Thanks guys, you all helped a lot.

Public Sub AdvanceChartData()
Dim cht As Chart
Dim sr As Series
Dim i As Long, j As Long
Dim arrFormula As Variant
Dim curXValues As String, newXValues As String
Dim curValues As String, newValues As String

For i = 1 To ActiveSheet.ChartObjects.Count
Set cht = ActiveSheet.ChartObjects(i).Chart
For Each sr In cht.SeriesCollection
arrFormula = Split(sr.Formula, ",")
curXValues = arrFormula(1)
curValues = arrFormula(2)
newXValues = MoveDataRange(curXValues, 1)
newValues = MoveDataRange(curValues, 1)

sr.Formula = arrFormula(0) & "," & newXValues & "," & newValues &
"," & arrFormula(3)

Next
Next
End Sub

Public Function MoveDataRange(strRange As String, lngMoveBy As Long)
Dim loc As Long
Dim locStartDS As Long
Dim locColon As Long
Dim locEndDS As Long
Dim lngFromRow As Long
Dim lngToRow As Long

locStartDS = InStr(1, strRange, "$")
locStartDS = InStr(locStartDS + 1, strRange, "$")
locColon = InStr(locStartDS + 1, strRange, ":")
lngFromRow = CLng(Mid(strRange, locStartDS + 1, locColon - (locStartDS +
1)))

locEndDS = InStrRev(strRange, "$")
lngToRow = CLng(Mid(strRange, locEndDS))

MoveDataRange = Mid(strRange, 1, locStartDS) & (lngFromRow + lngMoveBy) &
Mid(strRange, locColon, (locEndDS + 1) - locColon) & (lngToRow + lngMoveBy)

End Function
--
Disregard, this is so I can find my post later.
***postedbyJay***


"Tom Ogilvy" wrote:

http://j-walk.com/ss/excel/tips/tip83.htm

that should help with the xValues, etc

--
Regards,
Tom Ogilvy


"Jay" wrote:

I found a small problem with this named range solution.

I have 30+ charts I need to create named ranges for. With 3+ series in each
chart.

I think I might be farther ahead if I can find a way to modify the XValues
and Values instead. That way it won't be dependant on the named ranges, and
then I won't have to create them all. ;)

Any ideas?
--
Disregard, this is so I can find my post later.
***postedbyJay***


" wrote:

One thing to note when using named ranges for chart series, ensure you
name your range for the worksheet only and not the workbook.

i.e. Sheet1!NamedRange

Then when refering to the name range you will need to put Sheet1!
NamedRange in the chart series.

Regards,

Toyin.

ps - I hope you can find your post later!


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF/COUNT/AVERAGE... Value returned is incorrect. Rebekah Excel Worksheet Functions 3 September 28th 07 04:25 PM
F1 help for ChartObjects John Excel Programming 1 October 21st 06 02:36 AM
ChartObjects Scott Excel Programming 1 June 30th 06 12:23 AM
Datedif incorrect month count - February problem?? JMKCT Excel Worksheet Functions 4 December 14th 05 03:36 PM
ChartObjects Nick Excel Programming 2 August 19th 04 12:04 PM


All times are GMT +1. The time now is 11:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"