+ Reply to Thread
Results 1 to 11 of 11

Return targeted columns from an array of columns

Hybrid View

  1. #1
    Registered User
    Join Date
    08-08-2013
    Location
    Cambridge
    MS-Off Ver
    Win7 Office 2010
    Posts
    34

    Return targeted columns from an array of columns

    Hi,

    I am looking for a formula that will seek through an array of columns and return only those columns that contain a specific key word, in this case "TRUE". See the example workbook below as an example of the columns that I am referring to. I want to return only those columns (yes whole columns) that have "TRUE" in them. Could someone look into this for me?

    Thank you kindly ^_^

    Book2.xls

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,411

    Re: Return targeted columns from an array of columns

    And where do you want those columns returned to? Are you saying that you want to delete the columns that have FALSE in row 1?

    Pete

  3. #3
    Registered User
    Join Date
    08-08-2013
    Location
    Cambridge
    MS-Off Ver
    Win7 Office 2010
    Posts
    34

    Re: Return targeted columns from an array of columns

    I mean I want to return a copy of all the columns containing TRUE to the new worksheet

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,411

    Re: Return targeted columns from an array of columns

    You could do this using an array formula on Sheet2, but as you have so much data I think it would be better to use a helper row on Sheet1 (e.g. by inserting a new row1 on that sheet and putting a formula in those new cells), and then in Sheet2 you would just have a normally-entered formula using INDEX and MATCH. The helper row can be hidden, so that Sheet1 will look the same as you have now - is that an acceptable approach?

    Pete

  5. #5
    Registered User
    Join Date
    08-08-2013
    Location
    Cambridge
    MS-Off Ver
    Win7 Office 2010
    Posts
    34

    Re: Return targeted columns from an array of columns

    No I do not want to delete the colums that have FALSE in them. I want to return the specified columns (the ones containing TRUE) to a new worksheet, say Sheet 2

  6. #6
    Registered User
    Join Date
    08-08-2013
    Location
    Cambridge
    MS-Off Ver
    Win7 Office 2010
    Posts
    34

    Re: Return targeted columns from an array of columns

    Im not adept (yet) at using MATCH and INDEX functions. Could you provide an example, including an extra 'helper' row in Sheet1 as you mentioned above please?

    Thank you

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,411

    Re: Return targeted columns from an array of columns

    In the attached file I have inserted a new row 1 in Sheet1 and put this formula in B1:

    Formula: copy to clipboard
    =IF(B2,MAX($A1:A1)+1,"")


    which is then copied across to cell AY1. It identifies the columns that meet the criteria, and gives each one a unique sequential number. I've coloured this blue to show that it is a helper row (which can be hidden once it is set up).

    In Sheet2 I have put 1 in cell A1 and this formula in B1:

    Formula: copy to clipboard
    =IF(COLUMNS($A:B)-1>MAX(Sheet1!1:1),"",MATCH(COLUMNS($A:B)-1,Sheet1!1:1,0))


    and again, this is copied across to cell AX1. I've put this formula in B2:

    Formula: copy to clipboard
    =IF(B$1="","",INDEX(Sheet1!$2:$56,ROWS($1:1),B$1))


    which can then be copied down to B56 to return the data from the row given in B1. I've applied red to B2 and emboldened B3 to match the look of Sheet1, and then the block of formulae in B2:B56 can be copied across as far as you need them (i.e. to column AX), although I have only copied to column H to keep the file size down. I've also copied B3:B56 into column A, although as these are fixed values you could just copy that from Sheet1.

    You will need to copy the formulae across your sheet, and then you can play about with it - if you change any of the TRUE values to FALSE, or any of the FALSE values to TRUE in Sheet1, those changes will immediately be reflected in Sheet2.

    Hope this helps.

    Pete
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    08-08-2013
    Location
    Cambridge
    MS-Off Ver
    Win7 Office 2010
    Posts
    34

    Re: Return targeted columns from an array of columns

    That was spot on and solved my case perfectly, thank you Pete! ^_^ I have inserted the formulae as per your instructions and can now compile the columns that I need to work with. Once again, thanks. I've added a reputation star to your reply


    Quote Originally Posted by Pete_UK View Post
    In the attached file I have inserted a new row 1 in Sheet1 and put this formula in B1:

    Formula: copy to clipboard
    =IF(B2,MAX($A1:A1)+1,"")


    which is then copied across to cell AY1. It identifies the columns that meet the criteria, and gives each one a unique sequential number. I've coloured this blue to show that it is a helper row (which can be hidden once it is set up).

    In Sheet2 I have put 1 in cell A1 and this formula in B1:

    Formula: copy to clipboard
    =IF(COLUMNS($A:B)-1>MAX(Sheet1!1:1),"",MATCH(COLUMNS($A:B)-1,Sheet1!1:1,0))


    and again, this is copied across to cell AX1. I've put this formula in B2:

    Formula: copy to clipboard
    =IF(B$1="","",INDEX(Sheet1!$2:$56,ROWS($1:1),B$1))


    which can then be copied down to B56 to return the data from the row given in B1. I've applied red to B2 and emboldened B3 to match the look of Sheet1, and then the block of formulae in B2:B56 can be copied across as far as you need them (i.e. to column AX), although I have only copied to column H to keep the file size down. I've also copied B3:B56 into column A, although as these are fixed values you could just copy that from Sheet1.

    You will need to copy the formulae across your sheet, and then you can play about with it - if you change any of the TRUE values to FALSE, or any of the FALSE values to TRUE in Sheet1, those changes will immediately be reflected in Sheet2.

    Hope this helps.

    Pete

  9. #9
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Return targeted columns from an array of columns

    Okay, I know this is not the most elegant solution (uses OFFSET and is an array formula for a large spreadsheet), but I thought it was a interesting challenge. This is what worked. Put this in cell A1 of Sheet2:
    =OFFSET(Sheet1!$A$1,ROW(),SMALL(--(Sheet1!$A$1:$AX$1)*COLUMN(Sheet1!$A$1:$AX$1),COUNTIF(Sheet1!$B$1:$AX$1,FALSE)+COLUMN()+1)-1)
    Enter with Ctrl-Shift-Enter, and then drag across and down the sheet.
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  10. #10
    Registered User
    Join Date
    08-08-2013
    Location
    Cambridge
    MS-Off Ver
    Win7 Office 2010
    Posts
    34

    Re: Return targeted columns from an array of columns

    Thank you Pauley, I've tried your formula but it just returned VALUE! in all cells. Thank you anyways, my issue is now solved ^_^

    Quote Originally Posted by Pauleyb View Post
    Okay, I know this is not the most elegant solution (uses OFFSET and is an array formula for a large spreadsheet), but I thought it was a interesting challenge. This is what worked. Put this in cell A1 of Sheet2:
    =OFFSET(Sheet1!$A$1,ROW(),SMALL(--(Sheet1!$A$1:$AX$1)*COLUMN(Sheet1!$A$1:$AX$1),COUNTIF(Sheet1!$B$1:$AX$1,FALSE)+COLUMN()+1)-1)
    Enter with Ctrl-Shift-Enter, and then drag across and down the sheet.

  11. #11
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Return targeted columns from an array of columns

    Based on your last post in this thread, its apparent that you are satisfied with the solution(s) you've received and have solved your question, but you haven't marked your thread as "SOLVED",as per our Forum Rule #9. I will do it for you this time.

    In future, to mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

+ 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. Simple data entry form above the targeted columns.
    By mrmikepan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-03-2013, 05:34 PM
  2. Replies: 5
    Last Post: 12-01-2012, 06:34 PM
  3. Replies: 2
    Last Post: 10-28-2012, 09:53 PM
  4. [SOLVED] "Run-time error '13': Type mismatch" when deleteing multiple cells from targeted columns
    By mweickdival in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-26-2012, 01:09 PM
  5. columns in excel to reflect array of values entered in previous two columns
    By netvasi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-19-2011, 01:12 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