T
travis
I've written a function called RemoveZeroSeries(inputrange As Range) As
Range
Its purpose is to take a range, weed out all the rows with nothing but
zeros in them and then return a new range which is the input range
minus the rows which only contain zeros.
I get "Runtime error '91': Object variable or With Block variable not
set"
And this happens on the very last line of the function, on this line:
RemoveZeroSeries = chartable.Address
Full code follows:
Private Sub RemoveEmptyChartSeries_Click()
Range("IncomeChartNominalNoZeros").Name =
RemoveZeroSeries(Range("IncomeChartNominalData"))
' the chart didn't work either, but I've got to fix the function before
I can call it!
'ActiveSheet.ChartObjects("Chart 5").Activate
'ActiveChart.SetSourceData Source:=Sheets("Projection
1").RemoveZeroSeries(IncomeChartNominal), _
' PlotBy:=xlRows
'ActiveChart.SeriesCollection(1).XValues = Range("ProjectionYears")
End Sub
Private Function RemoveZeroSeries(inputrange As Range) As Range
Dim DownCounter, AcrossCounter, NumberOfRows As Integer
Dim temprange, chartable, upperleft As Range
' delete the next two lines for the function
'Dim inputrange As Range
'Set inputrange = Range("IncomeChartNominal")
MsgBox "There are " & inputrange.Rows.Count & " rows in the inputrange"
NumberOfRows = inputrange.Rows.Count
Set upperleft = inputrange.Resize(1, 1)
MsgBox "The Upper Left Cell is at " & upperleft.Address
' Find the first series which isn't all zeros, and name its range
"chartable"
For DownCounter = 0 To NumberOfRows
For AcrossCounter = 1 To (1 + Range("YearsProjection").Value)
If Not upperleft.Offset(DownCounter, AcrossCounter).Value = 0 Then
Set chartable = Range(upperleft.Offset(DownCounter, 0).Address &
":" & upperleft.Offset(DownCounter, 1 +
Range("YearsProjection").Value).Address)
GoTo GotFirstChartRangeSoBreakOutOfLoop
End If
Next AcrossCounter
Next DownCounter
GotFirstChartRangeSoBreakOutOfLoop:
' Now build up the rest of the range by adding additional ranges which
also have non zeros
For DownCounter = 0 To NumberOfRows
For AcrossCounter = 1 To (1 + Range("YearsProjection").Value)
If Not upperleft.Offset(DownCounter, AcrossCounter).Value = 0 Then
Set temprange = Range(upperleft.Offset(DownCounter, 0).Address &
":" & upperleft.Offset(DownCounter, 1 +
Range("YearsProjection").Value).Address)
Set chartable = Union(chartable, temprange)
AcrossCounter = 1
GoTo ThisSeriesHasAtLeastOneNonZeroSoMoveOnToTheNextOne
End If
Next AcrossCounter
ThisSeriesHasAtLeastOneNonZeroSoMoveOnToTheNextOne:
Next DownCounter
MsgBox "Chartable: " & chartable.Address
RemoveZeroSeries = chartable.Address
End Function
Range
Its purpose is to take a range, weed out all the rows with nothing but
zeros in them and then return a new range which is the input range
minus the rows which only contain zeros.
I get "Runtime error '91': Object variable or With Block variable not
set"
And this happens on the very last line of the function, on this line:
RemoveZeroSeries = chartable.Address
Full code follows:
Private Sub RemoveEmptyChartSeries_Click()
Range("IncomeChartNominalNoZeros").Name =
RemoveZeroSeries(Range("IncomeChartNominalData"))
' the chart didn't work either, but I've got to fix the function before
I can call it!
'ActiveSheet.ChartObjects("Chart 5").Activate
'ActiveChart.SetSourceData Source:=Sheets("Projection
1").RemoveZeroSeries(IncomeChartNominal), _
' PlotBy:=xlRows
'ActiveChart.SeriesCollection(1).XValues = Range("ProjectionYears")
End Sub
Private Function RemoveZeroSeries(inputrange As Range) As Range
Dim DownCounter, AcrossCounter, NumberOfRows As Integer
Dim temprange, chartable, upperleft As Range
' delete the next two lines for the function
'Dim inputrange As Range
'Set inputrange = Range("IncomeChartNominal")
MsgBox "There are " & inputrange.Rows.Count & " rows in the inputrange"
NumberOfRows = inputrange.Rows.Count
Set upperleft = inputrange.Resize(1, 1)
MsgBox "The Upper Left Cell is at " & upperleft.Address
' Find the first series which isn't all zeros, and name its range
"chartable"
For DownCounter = 0 To NumberOfRows
For AcrossCounter = 1 To (1 + Range("YearsProjection").Value)
If Not upperleft.Offset(DownCounter, AcrossCounter).Value = 0 Then
Set chartable = Range(upperleft.Offset(DownCounter, 0).Address &
":" & upperleft.Offset(DownCounter, 1 +
Range("YearsProjection").Value).Address)
GoTo GotFirstChartRangeSoBreakOutOfLoop
End If
Next AcrossCounter
Next DownCounter
GotFirstChartRangeSoBreakOutOfLoop:
' Now build up the rest of the range by adding additional ranges which
also have non zeros
For DownCounter = 0 To NumberOfRows
For AcrossCounter = 1 To (1 + Range("YearsProjection").Value)
If Not upperleft.Offset(DownCounter, AcrossCounter).Value = 0 Then
Set temprange = Range(upperleft.Offset(DownCounter, 0).Address &
":" & upperleft.Offset(DownCounter, 1 +
Range("YearsProjection").Value).Address)
Set chartable = Union(chartable, temprange)
AcrossCounter = 1
GoTo ThisSeriesHasAtLeastOneNonZeroSoMoveOnToTheNextOne
End If
Next AcrossCounter
ThisSeriesHasAtLeastOneNonZeroSoMoveOnToTheNextOne:
Next DownCounter
MsgBox "Chartable: " & chartable.Address
RemoveZeroSeries = chartable.Address
End Function