+ Reply to Thread
Results 1 to 14 of 14

VBA to select all ranges stored in array at once

  1. #1
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    VBA to select all ranges stored in array at once

    Hi all

    Was working on some code for OP...I got to a point where I wanted to select all the ranges stored in the array at once and did not know how to....
    The workaround is code in red....However only works in this case but is dependent upon the value of ii after the loop.
    Please put me outta my misery...Thanks.
    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: VBA to select all ranges stored in array at once

    This may help explain

    Please Login or Register  to view this content.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: VBA to select all ranges stored in array at once

    Make a function that copies this

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: VBA to select all ranges stored in array at once

    Maybe like this?

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: VBA to select all ranges stored in array at once

    A new function to add to my collection:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to select all ranges stored in array at once

    Hi guys...

    Thanks for responses..I understand the concept however am trying to incorporate.
    The specific ranges are not known....Need to be found then stored, then all selected at once....
    See attached...
    Attached Files Attached Files

  7. #7
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: VBA to select all ranges stored in array at once

    Try...
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to select all ranges stored in array at once

    @CK76

    Excellent solution, thanks...A more suitable solution I might add...Works flawlessly, however, still does not put me out of my misery....
    Need to fix my code if possible....Driving me crazy....

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to select all ranges stored in array at once

    Really...is this it...
    Please Login or Register  to view this content.
    Edited...
    So much still to learn...
    Last edited by sintek; 07-26-2017 at 01:24 PM.

  10. #10
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: VBA to select all ranges stored in array at once

    I see, using array only you'd do it like below.

    Please Login or Register  to view this content.

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to select all ranges stored in array at once

    @ CK176...do understand your part...
    Please Login or Register  to view this content.

    Is this, however, the only fix....to my code or am i missing something....
    Please Login or Register  to view this content.

  12. #12
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: VBA to select all ranges stored in array at once

    Well, one thing. You are doing "ReDim Preserve" AFTER you add 1 to ii. That's causing array to add blank element.

    So you should remove "ReDim Preserve RngArr(0)"

    And change code inside your IF statement to something like below.
    Please Login or Register  to view this content.
    Edit: Alternately you can check if "RngArr(iii) Is Nothing" and skip if it is.
    Last edited by CK76; 07-26-2017 at 02:03 PM. Reason: See Edit:

  13. #13
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to select all ranges stored in array at once

    Cool bananas..Tx

  14. #14
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: VBA to select all ranges stored in array at once

    Quote Originally Posted by sintek View Post
    @CK76

    A more suitable solution I might add...Works flawlessly
    Does exactly the same as the general function I wrote for you ^.^

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Activate sheet stored in array
    By sintek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-17-2017, 08:38 AM
  2. How to Transfer Stored Data in Array to Table?
    By realcapone in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-31-2017, 02:28 PM
  3. [SOLVED] EVALUATE an R1C1 formula currently stored in an array
    By JBeaucaire in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-07-2016, 11:01 PM
  4. Select multiple sheets that are stored in an array (VBA)
    By jkj115 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-26-2015, 06:56 PM
  5. [SOLVED] Macro to select and open filepath stored at worksheet
    By Faridwahidi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-01-2014, 04:32 AM
  6. How to select a cell based on a row number I have stored
    By ChrisF79 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2013, 02:11 PM
  7. select variables ranges, copy to array, paste the array in new workbook
    By Mathew in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-01-2005, 05:06 AM

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