+ Reply to Thread
Results 1 to 16 of 16

Max Length in Array

  1. #1
    Forum Contributor
    Join Date
    06-03-2008
    Posts
    387

    Max Length in Array

    Is there a faster way to get the max length of strings stored in an array besides looping through each item in the array and checking the length?
    Last edited by yawnzzzz; 07-20-2010 at 05:27 PM.

  2. #2
    Administrator JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Max Length in Array

    I don't think so, but as long as the array is in memory, the complete loop would be near-on instantaneous.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,646

    Re: Max Length in Array

    If your array is a range, e.g. A1:D8

    Please Login or Register  to view this content.

  4. #4
    Administrator JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Max Length in Array

    I get error 2036 for c02.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,646

    Re: Max Length in Array

    A1:D8 all contain characters ?

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,646

    Re: Max Length in Array

    Nothing further, your honour...
    See the attachment.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    06-03-2008
    Posts
    387

    Re: Max Length in Array

    Afraid my example is not a range.

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,646

    Re: Max Length in Array

    Why don't you tell us what kind of array it is ?

  9. #9
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Max Length in Array

    You'll need to loop I think, assuming you can't track it when populating the array initially.
    Remember what the dormouse said
    Feed your head

  10. #10
    Forum Contributor
    Join Date
    06-03-2008
    Posts
    387

    Re: Max Length in Array

    I'm already tracking it when populating the array initially, so it sounds like that might be my best bet. I'm just dealing with the potential to have such a large amount of data that I'm looking for anything that might run just a fraction of a second faster.

  11. #11
    Administrator JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Max Length in Array

    My sample I used an entire column, so A:A won't work in this syntax, but I'm still very happy to see this [....] syntax that appears to allow standard worksheet formula verbiage. Very useful.

  12. #12
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,677

    Re: Max Length in Array

    It's just a shorthand notation for the Evaluate function, JB. In common usage, it serves to add a function where none is needed.
    Entia non sunt multiplicanda sine necessitate

  13. #13
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Max Length in Array

    It's also slower than Evaluate, FWIW.

  14. #14
    Administrator JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Max Length in Array

    Quote Originally Posted by shg View Post
    It's just a shorthand notation for the Evaluate function, JB.
    Quote Originally Posted by romperstomper
    It's also slower than Evaluate, FWIW.
    Ah, none of that is obvious! Thanks for that.


    Quote Originally Posted by shg
    In common usage, it serves to add a function where none is needed.
    Can you explain what you mean by that?

  15. #15
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,677

    Re: Max Length in Array

    Run this:

    Please Login or Register  to view this content.
    Last edited by shg; 07-20-2010 at 06:07 PM.

  16. #16
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,646

    Re: Max Length in Array

    I thought this line was on maxlength in an array ?
    Please Login or Register  to view this content.
    Last edited by snb; 07-21-2010 at 05:51 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1