Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default quickest way to find last "used" row in a 2D array? (repost)

I have a 2D variant array that is populated with a large worksheet range
(large enough to ensure that I won't miss any data from some variable length
reports).

The actual number of 'used' rows in the array may change over time as well,
as there are pieces of code that may add or remove records (rows).

Right now, I'm looping the entire array every time I need to compare data,
which is inefficient because sometimes only a fraction of the array is
actually populated with data. I do recursive looping, so it adds a lot of
processing time.

Is there a parameter I can check that would tell me the last 'used' row of
an array? UBound gives the size of the array regardless of whether it is
populated, so probably isn't the right direction for me to go.

One option would be to loop the array to find the last used row directly,
but I'm not sure that would save me much time over just looping the array to
compare data in the first place.

Many thanks,
Keith


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default quickest way to find last "used" row in a 2D array? (repost)

Why don't you get the last used row from the range rather than from the
array?
Something like: MsgBox Range(Cells(1), Cells(10,
10)).SpecialCells(xlLastCell).Row
Or even better assign your array to the used range, so you can forget about
the last used
row in the array.
In any case you don't have to loop the whole array as when you loop from
back to front
you can do an exit when you find a non-empty element.

RBS


"ker_01" wrote in message
...
I have a 2D variant array that is populated with a large worksheet range
(large enough to ensure that I won't miss any data from some variable
length reports).

The actual number of 'used' rows in the array may change over time as
well, as there are pieces of code that may add or remove records (rows).

Right now, I'm looping the entire array every time I need to compare data,
which is inefficient because sometimes only a fraction of the array is
actually populated with data. I do recursive looping, so it adds a lot of
processing time.

Is there a parameter I can check that would tell me the last 'used' row of
an array? UBound gives the size of the array regardless of whether it is
populated, so probably isn't the right direction for me to go.

One option would be to loop the array to find the last used row directly,
but I'm not sure that would save me much time over just looping the array
to compare data in the first place.

Many thanks,
Keith


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default quickest way to find last "used" row in a 2D array? (repost)


"RB Smissaert" wrote in message
...
Why don't you get the last used row from the range rather than from the
array?
Something like: MsgBox Range(Cells(1), Cells(10,
10)).SpecialCells(xlLastCell).Row

I can do that on the initial load, but the size of the used data area
changes throughout my procedures. I was hoping to avoid tracking the 'used'
size with separate variables, if for no other reason that having a separate
variable makes it harder to troubleshoot if I miss incrementing it
somewhere.

Or even better assign your array to the used range, so you can forget
about the last used
row in the array.

That works for the initial assignment, but forces redim preserves when I
need to add items. That might still be ok, I just try to avoid that overhead
when possible, again to avoid human errors in the code at different points
where it might need resizing

In any case you don't have to loop the whole array as when you loop from
back to front
you can do an exit when you find a non-empty element.

Yep, that's kind of what I ended up with- but I have to check multiple
fields, as not every field in every 'row' is used. I was hoping there might
have been the equivalent of a used range parameter so I could use just one
number for each loop without all the extra checking. It doesn't sound like
there is a built-in parameter, so what I've got (although clunky) may be as
good as it gets.

Thanks,
Keith


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default quickest way to find last "used" row in a 2D array? (repost)


"RB Smissaert" wrote in message
...
Why don't you get the last used row from the range rather than from the
array?
Something like: MsgBox Range(Cells(1), Cells(10,
10)).SpecialCells(xlLastCell).Row

I can do that on the initial load, but the size of the used data area
changes throughout my procedures. I was hoping to avoid tracking the 'used'
size with separate variables, if for no other reason that having a separate
variable makes it harder to troubleshoot if I miss incrementing it
somewhere.

Or even better assign your array to the used range, so you can forget
about the last used
row in the array.

That works for the initial assignment, but forces redim preserves when I
need to add items. That might still be ok, I just try to avoid that overhead
when possible, again to avoid human errors in the code at different points
where it might need resizing

In any case you don't have to loop the whole array as when you loop from
back to front
you can do an exit when you find a non-empty element.

Yep, that's kind of what I ended up with- but I have to check multiple
fields, as not every field in every 'row' is used. I was hoping there might
have been the equivalent of a used range parameter so I could use just one
number for each loop without all the extra checking. It doesn't sound like
there is a built-in parameter, so what I've got (although clunky) may be as
good as it gets.

Thanks,
Keith



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
Whats wrong with this? MyWBAccRep.Sheets("Volumes").Cells.Find("latest").Copy.Offset(0, Simon[_2_] Excel Programming 2 August 11th 08 01:29 PM
How to find largest value "<=" when array is in descending order? [email protected] Excel Worksheet Functions 3 September 22nd 07 06:48 PM
Listbox header inside VBA (Array("Head1", "Head2", ...) Alex St-Pierre Excel Programming 2 October 25th 06 09:28 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
If changed array formula reduce ""\""\""\ - signs to #Missing, will it make ... Maria J-son[_2_] Excel Programming 2 March 5th 06 12:20 PM


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