I've been looking through the threads and haven't found the solution to my problem. I'm trying to make this work were I don't have to add the offset formula in the data range, my users wouldn't know how to do this. I'm trying to automate the refresh of the seriescollection of the charts. There are about 10-12 charts that need to have the added column that is updated every quarter.
Here's what I have so far and I'm hoping someone can point me to my errors:
Thanks for your time and help looking through my messy code
Here's what I have so far and I'm hoping someone can point me to my errors:
Code:
Private Sub CommandButton1_Click()
Dim lstCol As Integer
Dim xlrow1 As Integer, xlrow2 As Integer
'Dim newrng As Range
Sheets("cost and space").Select
datasheet = ActiveSheet.Name
msg = InputBox("What's the quarter to start with?", , "Q3'01")
Range("A1").Select
Cells.Find(What:=msg, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
True, SearchFormat:=False).Activate
startcol = ActiveCell.Column
'Find the last added column
Do
ActiveCell.Offset(0, 1).Select
Loop Until IsEmpty(ActiveCell)
lstCol = ActiveCell.Column - 1
Dim sh
Dim myChart As Chart
For i = 0 To Worksheets.Count
For Each sh In ActiveSheet.ChartObjects
sh.Select
For j = 1 To ActiveChart.SeriesCollection.Count
With ActiveChart
With .SeriesCollection(j)
myrange = .Formula
myrange1 = Split(myrange, ":")(0)
myrangeend = Split(Split(myrange, "!")(0), "(")(1)
startnum = Application.Find(":", myrange, 1) + 1
myrange2 = Mid(myrange, startnum, 6)
myrange2 = Split(myrange2, ",")(0)
xlrow = Split(Split(myrange2, "$")(2), ",")(0)
xlrow1 = xlrow
myrange3 = Right(myrange, Application.Find(datasheet & "'!", myrange, startnum) - startnum - 2)
If IsError(Application.Find("$", myrange3, 1)) Then
xlrow = Split(myrange3, ",")(0)
Else: xlrow = Split(Split(myrange3, "$")(1), ",")(0)
End If
xlrow2 = xlrow
newrng = myrange1 & ":" & Cells(xlrow1, lstCol).Address & myrangeend & "!" & Cells(xlrow2, startcol).Address _
& ":" & Cells(xlrow2, lstCol).Address & Split(myrange3, xlrow2)(1)
End With
With .SeriesCollection(j)
.Values = myrange1 & ":" & Cells(xlrow1, lstCol).Address & myrangeend & "!" & Cells(xlrow2, startcol).Address _
& ":" & Cells(xlrow2, lstCol).Address & Split(myrange3, xlrow2)(1)
End With
End With
Next
Next
i = i + 1
ActiveSheet.Next.Select
Next