+ Reply to Thread
Results 1 to 3 of 3

Store Multiple Non Sequential Column References in Array and then Select these columns

Hybrid View

Jimbo77 Store Multiple Non Sequential... 04-24-2014, 04:55 PM
Kaper Re: Store Multiple Non... 04-25-2014, 01:47 AM
Jimbo77 Re: Store Multiple Non... 04-25-2014, 02:12 PM
  1. #1
    Registered User
    Join Date
    03-31-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    57

    Store Multiple Non Sequential Column References in Array and then Select these columns

    Hello all

    I need some code that does the follow:

    1) Starting in Column A looks to see if any if any cells in column contain the number 1.

    2) If any do then store this column reference in an array.

    3) Move on to next column.

    4) Repeat 2) and 3) until no data in column

    5) Select the columns from the array


    Is this possible?

    Jim

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,891

    Re: Store Multiple Non Sequential Column References in Array and then Select these columns

    You can add column one by one to a range by means of UNION

    Something like
    dim myrange as range, i as long
    for i = 1 to 100 
      if your condition for column i is true then
        if myrange is nothing then 
          set myrange = columns(i)
       else
         set myrange = union(myrange,columns(i)) 
       end if
     end if 
    next i
    if myrange is nothing then
      msgbox "sorry nothing found"
    else
      ' do the job :)
    end if
    PS. For checking if column contains particular value you could use either Find or worksheetfunction.countif
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    03-31-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: Store Multiple Non Sequential Column References in Array and then Select these columns

    Awesome - this was the key bit for me to use:

    if myrange is nothing then 
          set myrange = columns(i)
       else
         set myrange = union(myrange,columns(i)) 
       end if

+ 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. Replies: 7
    Last Post: 01-30-2013, 03:48 AM
  2. Copy non-sequential columns with headers (from multiple sheets) to one consolidated sheet
    By constantmallee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-18-2012, 02:24 PM
  3. Select range dynamically using relative row and column references
    By gtol in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-01-2012, 06:43 AM
  4. Filter 2 or more columns, store result in one column
    By ZipGuy1961 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2009, 07:15 PM
  5. array/lookup help - multiple references over multiple colums
    By cards52 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-22-2009, 03:04 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