LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Baffled by calling a private function

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

 
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
Calling a private macro Nick Smith[_2_] Excel Programming 5 June 8th 06 12:03 PM
Calling Private Sub/Function AMK4[_36_] Excel Programming 5 February 4th 06 01:47 AM
Calling a Private Sub ben Excel Programming 8 December 8th 04 10:18 PM
Calling a private sub Bob Phillips[_7_] Excel Programming 3 July 29th 04 02:59 AM
calling private subs dunlklee Excel Programming 1 December 16th 03 08:40 AM


All times are GMT +1. The time now is 10:33 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"