+ Reply to Thread
Results 1 to 22 of 22

Formula to extract data from range

Hybrid View

  1. #1
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,176

    Formula to extract data from range

    Does anyone have a dynamic array formula to take data, filter it and remove some columns?

    On a separate sheet show only the columns with the yellow title and rows where column M is "YES"
    The number of rows will vary although the column count is fixed.

    I've attached a file with a mock up showing the desired result.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,275

    Re: Formula to extract data from range

    Try

    Formula: copy to clipboard
    =CHOOSECOLS(VSTACK(Data!A1:N1,FILTER(Data!A2:N17,Data!M2:M17="YES")),3,7,9,10,11,13)
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,249

    Re: Formula to extract data from range

    Voila:

    Formula: copy to clipboard
    =CHOOSECOLS(FILTER(Data!$A:$N,(Data!$M:$M="YES")+(Data!$M:$M="EIGHT")),3,7,9,10,11,13)
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,990

    Re: Formula to extract data from range

    Try this,
    =CHOOSECOLS(VSTACK(Data!A1:N1,FILTER(Data!A2:N1000,Data!M2:M1000="YES")),3,7,9,10,11,13)
    Attached Files Attached Files

  5. #5
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,176

    Re: Formula to extract data from range

    Thanks guys, really appreciate the responses, all of which of course work

  6. #6
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,990

    Re: Formula to extract data from range

    You are welcome.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,249

    Re: Formula to extract data from range

    I will just mention that I used references to the entire columns because for this particular formula, Excel knows which cells are actually used. In some cases with array formulas, using the entire column would force Excel to evaluate all million+ rows, causing a performance catastrophe. But not in this case.

  8. #8
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,176

    Re: Formula to extract data from range

    I wonder, is it possible to sort by Column A and then by Column B in the result as well?

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,249

    Re: Formula to extract data from range

    I was able to do that with a restructuring of the formula

    Formula: copy to clipboard
    =CHOOSECOLS(VSTACK(Data!$A$1:$N$1,SORT(FILTER(Data!$A:$N,Data!M:M="YES"),{3,7})),3,7,9,10,11,13)


    I did the sort on the inside to avoid sorting the headings. This means that the sort index number refer to the original data, not the result

  10. #10
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,176

    Re: Formula to extract data from range

    Thank you that's perfect. I was trying to do the sort on the inside which wasn't successful.

  11. #11
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2019
    Posts
    4,542

    Re: Formula to extract data from range

    With selected column headers in row 1:
    A2=CHOOSECOLS(FILTER(Data!A:N,Data!M:M="YES"),MATCH(A1:F1,Data!A1:N1,0))

  12. #12
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2019
    Posts
    4,542

    Re: Formula to extract data from range

    This one better, no limit to number of selected columns: =CHOOSECOLS(FILTER(Data!A:N,Data!M:M="YES"),MATCH(TOROW(1:1,1),Data!A1:N1,0))

  13. #13
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2019
    Posts
    4,542

    Re: Formula to extract data from range

    To sort by 1st 2 columns: =SORT(CHOOSECOLS(FILTER(Data!A:N,Data!M:M="YES"),MATCH(TOROW(1:1,1),Data!A1:N1,0)),{1,2},{1,1})

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,089

    Re: Formula to extract data from range

    Late to the party, as usual

    I tend to do these things step by step, assigning variables to each stage. That way, I can display the variables as I go along to check that I’m getting what I expect. You can always consolidate later but I find the logical build up helps me to check the process.

    So, I start with rng, then sorted range, srng, then filtered sorted range, fsrng, etc., each building on the previous one. And, eventually, I bite the bullet and put it all together.

    Anyway, for what it's worth:
    Formula: copy to clipboard
     =LET(lr,COUNTA(Data!A:A),rng,Data!A2:INDEX(Data!N:N,lr),hdr,Data!A1:N1,srng,SORT(rng,{3,7},{1,1}),fsrng,FILTER(srng,INDEX(rng,,13)="YES"),     CHOOSECOLS(VSTACK(hdr,fsrng),3,7,9,10,11,13))


    Note that I have also calculated a last range variable, lr, based on column A to avoid potential full column references.


    Based on feedback, this is the corrected version:

    Formula: copy to clipboard
    =LET(lr,COUNTA(Data!A:A),rng,Data!A2:INDEX(Data!N:N,lr),hdr,Data!A1:N1,srng,SORT(rng,{3,7},{1,1}),fsrng,FILTER(srng,INDEX(srng,,13)="YES"),cc,CHOOSECOLS(VSTACK(hdr,fsrng),3,7,9,10,11,13),cc)


    The error was here: FILTER(srng,INDEX(rng,,13)="YES")
    Last edited by TMS; 01-09-2025 at 10:46 AM. Reason: Update formula
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  15. #15
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,176

    Re: Formula to extract data from range

    @josephteh
    Struggling with this one. It seems to be referencing the first row of the Result sheet?

    @TMS
    I like the idea of breaking it down using LET and getting the row count, but in the results the column EIGHT is a mix of YES and NO when it should be filtered for YES.

  16. #16
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2019
    Posts
    4,542

    Re: Formula to extract data from range

    Quote Originally Posted by ByteMarks View Post
    @josephteh
    Struggling with this one. It seems to be referencing the first row of the Result sheet?
    That's correct. And, you can add in any column headers.

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,089

    Re: Formula to extract data from range

    Quote Originally Posted by ByteMarks View Post
    @josephteh
    Struggling with this one. It seems to be referencing the first row of the Result sheet?

    @TMS
    I like the idea of breaking it down using LET and getting the row count, but in the results the column EIGHT is a mix of YES and NO when it should be filtered for YES.
    I'll have a look at it. I'm sure it was ok at one point as I had it all matched up against the original expected results

  18. #18
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,176

    Re: Formula to extract data from range

    Oh I get it. So you manually add the column headings you want. Thanks for the input.

  19. #19
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,176

    Re: Formula to extract data from range

    I put the sort and filter the other way round which seems to have fixed it

    Formula: copy to clipboard

    =LET(lr,COUNTA(Data!A:A),
    rng,Data!A2:INDEX(Data!N:N,lr),
    hdr,Data!A1:N1,
    frng,FILTER(rng,INDEX(rng,,13)="YES"),
    srng,SORT(frng,{3,7},{1,1}),

    CHOOSECOLS(VSTACK(hdr,srng),3,7,9,10,11,13))

  20. #20
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,089

    Re: Formula to extract data from range

    This is the fixed version:
    Formula: copy to clipboard
    =LET(lr,COUNTA(Data!A:A),rng,Data!A2:INDEX(Data!N:N,lr),hdr,Data!A1:N1,srng,SORT(rng,{3,7},{1,1}),fsrng,FILTER(srng,INDEX(srng,,13)="YES"),cc,CHOOSECOLS(VSTACK(hdr,fsrng),3,7,9,10,11,13),cc)


    Just for fun:
    Formula: copy to clipboard
    =LET(lr,COUNTA(Data!A:A),rng,Data!A2:INDEX(Data!N:N,lr),hdr,Data!A1:N1,srng,SORT(rng,{3,7},{1,1}),fsrng,FILTER(srng,INDEX(srng,,13)="YES"),cc,CHOOSECOLS(VSTACK(hdr,fsrng),XMATCH(TEXTSPLIT("HAPPY,CHRISTMAS,AND,NEW,YEAR,EIGHT",","),hdr)),cc)


    Formula: copy to clipboard
    =LET(lr,COUNTA(Data!A:A),rng,Data!A2:INDEX(Data!N:N,lr),hdr,Data!A1:N1,srng,SORT(rng,{3,7},{1,1}),fsrng,FILTER(srng,INDEX(srng,,13)="YES"),cc,CHOOSECOLS(VSTACK(hdr,fsrng),XMATCH(TEXTSPLIT("HAPPY,CHRISTMAS,AND,NEW,YEAR",","),hdr)),cc)

  21. #21
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,176

    Re: Formula to extract data from range

    Fantastic.

  22. #22
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,089

    Re: Formula to extract data from range

    You're welcome. Thanks for the rep.

+ 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] Formula to Extract Min and Max in a date range
    By Howardc1001 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-02-2025, 10:20 AM
  2. [SOLVED] Extract Maximum Formula in Range
    By Howardc1001 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-07-2024, 02:12 AM
  3. [SOLVED] Macro to Extract Data from Multiple Worksheets based on a Data Range
    By Coby Rock in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 09-25-2023, 02:58 AM
  4. Replies: 12
    Last Post: 04-07-2023, 11:46 PM
  5. [SOLVED] Excel function use to extract between range data without array Formula
    By sanjuss2 in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 03-04-2023, 09:49 AM
  6. [SOLVED] formula to extract max range used inside another formula and display in another cell
    By AndyJr in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-04-2018, 11:33 AM
  7. extract data by defining range using formula.
    By iqbal@khan in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-11-2014, 02:16 PM

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