Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Recursion in VBA macros?

I'm writing macros under Excel 2003/XP on a fairly powerful PC to process
financial data.

When I'm searching an almost full column for the next non-blank entry I
don't have any problem using recursion, but when the column is mostly blank
I wonder whether I'm doing the right thing.

Are there any guidelines for using recursion under VBA? I use instance
variables instead of locals, but that's about all I know.

Thanks for your help,
Peter


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Recursion in VBA macros?

Why would you use recursion for the next blank row?

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Peter Chatterton" wrote in message
...
I'm writing macros under Excel 2003/XP on a fairly powerful PC to process
financial data.

When I'm searching an almost full column for the next non-blank entry I
don't have any problem using recursion, but when the column is mostly

blank
I wonder whether I'm doing the right thing.

Are there any guidelines for using recursion under VBA? I use instance
variables instead of locals, but that's about all I know.

Thanks for your help,
Peter




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Recursion in VBA macros?

I'm calling 'getNextRow' and everytime it hits a blank row it calls itself
again.

Public Function getNextRow() As Boolean
lRow = lRow + 1
If lRow <= lMaxRow Then
getNextRow = True
Set r = rFundNameCol.Cells(lRow)
s = r
If s = "" Then _
getNextRow
Else
getNextRow = False
End If
End Function


"Bob Phillips" wrote in message
...
Why would you use recursion for the next blank row?

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Peter Chatterton" wrote in message
...
I'm writing macros under Excel 2003/XP on a fairly powerful PC to process
financial data.

When I'm searching an almost full column for the next non-blank entry I
don't have any problem using recursion, but when the column is mostly

blank
I wonder whether I'm doing the right thing.

Are there any guidelines for using recursion under VBA? I use instance
variables instead of locals, but that's about all I know.

Thanks for your help,
Peter






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Recursion in VBA macros?

A couple of things... One is that I would be inclined to avoid the instance
varables and stick with locals. The instance variables ( I assume you mean
globals) can be quite difficult to debug.

As for the first blank cell you can do that something like this

dim rng1 as range 'First blank
dim rng2 as range 'Last Blank

Sheets("Sheet1").select
set rng1= Sheets("Sheet1").Range("A1").end(xlDown)
msgbox rng1.address
set rng2 = Sheets("Sheet1").cells(rows.count, "a").end(xlUp).Offset(1,0)
msgbox rng2.address
--
HTH...

Jim Thomlinson


"Peter Chatterton" wrote:

I'm writing macros under Excel 2003/XP on a fairly powerful PC to process
financial data.

When I'm searching an almost full column for the next non-blank entry I
don't have any problem using recursion, but when the column is mostly blank
I wonder whether I'm doing the right thing.

Are there any guidelines for using recursion under VBA? I use instance
variables instead of locals, but that's about all I know.

Thanks for your help,
Peter



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Recursion in VBA macros?

That's incredibly inefficient, given the overhead that calling a
function requires. It also requires tons of stack space.

A simpler function would be:

Public Function getNextRow() As Boolean
For lRow = lRow + 1 To lMaxRow
If rFundNameCol.Cells(lRow).Value < vbNullString Then Exit For
Next lRow
getNextRow = lRow <= lMaxRow
End Function


In article ,
"Peter Chatterton" wrote:

Public Function getNextRow() As Boolean
lRow = lRow + 1
If lRow <= lMaxRow Then
getNextRow = True
Set r = rFundNameCol.Cells(lRow)
s = r
If s = "" Then _
getNextRow
Else
getNextRow = False
End If
End Function



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Recursion in VBA macros?

Thanks, that's much better than recursion.
Peter

"JE McGimpsey" wrote in message
...
That's incredibly inefficient, given the overhead that calling a
function requires. It also requires tons of stack space.

A simpler function would be:

Public Function getNextRow() As Boolean
For lRow = lRow + 1 To lMaxRow
If rFundNameCol.Cells(lRow).Value < vbNullString Then Exit For
Next lRow
getNextRow = lRow <= lMaxRow
End Function


In article ,
"Peter Chatterton" wrote:

Public Function getNextRow() As Boolean
lRow = lRow + 1
If lRow <= lMaxRow Then
getNextRow = True
Set r = rFundNameCol.Cells(lRow)
s = r
If s = "" Then _
getNextRow
Else
getNextRow = False
End If
End Function



Reply
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
Abort recursion Mike NG Excel Programming 2 June 29th 05 09:08 AM
Recursion Mike NG Excel Programming 4 June 2nd 05 11:07 PM
Worksheet_Change Recursion ARGHH! DBAL[_2_] Excel Programming 6 July 1st 04 11:55 PM
recursion depth, 'Out of stack space' in Quicksort marcel Excel Programming 0 April 21st 04 09:11 PM
Recursion with user defined functions bigJim Excel Programming 1 December 15th 03 01:00 PM


All times are GMT +1. The time now is 05:36 AM.

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

About Us

"It's about Microsoft Excel"