+ Reply to Thread
Results 1 to 14 of 14

VBA Arrays-A few useful functions

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    VBA Arrays-A few useful functions

    Why I am creating this thread:
    Firstly I should make clear that I am not the best qualified to write this thread (I only started learning arrays less than a month ago). I am creating this thread because I recently had an urgent need to rapidly learn how to use arrays and I was greatly helped by Excel Forum users so I wanted to give back in some small way. Hence this thread.

    What this thread is:
    A list of functions to allow array newbies (such as myself) to create/manipulate/write 1D & 2D arrays without requiring expert knowledge on how to work with arrays.

    Disclaimer:
    As I am new to arrays, I have no doubt that this code greatly needs improvement.
    As such, I take no responsibility if the code doesn't do what you expect - in other words, use at your own risk

    If you are experienced with arrays and can see anything that should change, please post in this thread so I can update the code. Thank you.

    I will try to update this thread soon to include some brief instructions on what the functions do and how best to apply them.


    Arrays Function Module No 1 (This deals with reading/writing arrays to/from Active/Closed/New workbook)
    Please Login or Register  to view this content.
    Last edited by mc84excel; 06-06-2013 at 11:11 PM. Reason: updated with latest version
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: VBA Arrays-A few useful functions

    Arrays Function Module No 2 (This mostly deals with manipulating arrays e.g. sorting/rebuilding etc.)
    Part 1 of 2

    Please Login or Register  to view this content.
    Last edited by mc84excel; 06-06-2013 at 11:12 PM. Reason: updated to latest version

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: VBA Arrays-A few useful functions

    Arrays Function Module No 2 - Part 2 of 2 (Copy & Paste into the same module as the Part 1)

    Please Login or Register  to view this content.
    Last edited by mc84excel; 06-06-2013 at 11:11 PM. Reason: updated to latest version

  4. #4
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: VBA Arrays-A few useful functions

    Moderators - I can't edit post #1 any more...

    Have now split the functions into 4 modules and am making many changes to the code (it needed it!). I only have time to upload the first module (more coming next week). It has a more consistent naming approach to arguments + explanations on the use/logic of the arguments.

    N.B. This code is incompatible with post #1s version. If you have used code from post#1, you will need to manually correct the arguments from all calling subs

    UPDATE: I have renamed the functions again (I thought "create" was a better choice then "build". Build implies creating in steps - like looping).

    Please Login or Register  to view this content.
    Last edited by mc84excel; 06-24-2013 at 08:17 PM.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Arrays-A few useful functions

    mc84excel,
    Thank you for sharing with us!
    My two cents contribution?
    I think most if not all the above arrays are functions, not procedures.
    Personally, I would prefer to use arrays on procedures for code efficiency.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Arrays-A few useful functions

    Quote Originally Posted by AB33 View Post
    Personally, I would prefer to use arrays on procedures for code efficiency.
    what does that mean? there is no difference between functions and subs other than the fact that functions (typically) return a value-neither is more efficient
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Arrays-A few useful functions

    What I meant!
    I normally use arrays in a loop, so instead of looping through a range,it is much faster to dump the range in to an array.
    By the way: nostalgia of Old hippie days with your new photo.

  8. #8
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: VBA Arrays-A few useful functions

    Hi mc84excel
    as an option your first function (Build2DArrayFromWSInActWB but not Build1Dor2DArrayFromWSInActWB)
    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: VBA Arrays-A few useful functions

    Quote Originally Posted by AB33 View Post
    I normally use arrays in a loop, so instead of looping through a range,it is much faster to dump the range in to an array.
    We agree on this. (My first module creates arrays from reading a range. I only use loops in arrays when I wish to create arrays from existing arrays).

  10. #10
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: VBA Arrays-A few useful functions

    Quote Originally Posted by nilem View Post
    Hi mc84excel
    as an option your first function (Build2DArrayFromWSInActWB but not Build1Dor2DArrayFromWSInActWB)
    Thanks for contributing this code. I prefer to have the option to return a 1D array from the same function however. (In some cases I wish to return a 1D array from a worksheet range)
    Last edited by mc84excel; 06-25-2013 at 06:56 PM.

  11. #11
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: VBA Arrays-A few useful functions

    Here is the updated part #4. (Updated Parts #2 & #3 in more recent posts)

    Please Login or Register  to view this content.
    Last edited by mc84excel; 06-26-2013 at 09:00 PM. Reason: Improved code

  12. #12
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: VBA Arrays-A few useful functions

    And the updated part #3 (updated part #2 to come). This needs tidying up. I am sure the BubbleSort function (2nd column part) could be written to be more efficient.

    Please Login or Register  to view this content.
    Last edited by mc84excel; 06-25-2013 at 06:56 PM.

  13. #13
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: VBA Arrays-A few useful functions

    Reworked. Latest version of arrays in attached workbook.
    Attached Files Attached Files
    Last edited by mc84excel; 07-11-2013 at 08:44 PM. Reason: New versions

  14. #14
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: VBA Arrays-A few useful functions

    Here is the latest version. It will probably be the last. If anyone wishes to take over and upload their own versions to this thread, be my guest. (Please provide brief explanations of the new functions/reason for changing existing functions, thanks)
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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