+ Reply to Thread
Results 1 to 17 of 17

Adapt this array formula to sort if possible

  1. #1
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Adapt this array formula to sort if possible

    This array formula copies data from a sheet "Items" with 11 dynamic ranges, to another sheet "Costs" and places all of the data from the eleven different dynamic ranges (columns) in a single column, in the same individual range order without spaces but unsorted.

    Any update to the "items" sheet is reflected in the "Costs" sheet but in the range order.

    =IFERROR(INDIRECT("Items!"&TEXT(SMALL(IF(Items!$A$2:$K$60<>"",ROW(Items!$A$2:$K$60)*10^4+COLUMN(Items!$A$2:$K$60)),ROWS($A$1:A1)),"R0000C0000"),0),"")

    Can this formula be adapted to sort the copied data A to Z, if so how would you do it.


    Many thanks

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Adapt this array formula to sort if possible

    Hi.

    It would seem then that non-uniqueness is not an issue for your set-up.

    Array formula**:

    =IFERROR(INDIRECT("Items!"&TEXT(MAX(IF(COUNTIF(Items!$A$2:$K$60,"<"&Items!$A$2:$K$60)=SMALL(IF(Items!$A$2:$K$60<>"",COUNTIF(Items!$A$2:$K$60,"<"&Items!$A$2:$K$60)),ROWS($1:1)),10^5*ROW(Items!$A$2:$K$60)+COLUMN(Items!$A$2:$K$60))),"R0C00000"),0),"")

    Note that 10^4 would not be sufficient for all ranges within a standard Excel workbook, though 10^5 would.

    Regards
    Click * below if this answer helped

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

  3. #3
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Adapt this array formula to sort if possible

    Thanks for helping.

    Your adapted formula, almost works perfectly. Just a couple of issues, the first item returned is a zero. and it doesn't handle additions to the items list correctly.

    I've attached a sample sheet for you.

    sorry, in the sample file the correction should read, A to Z Apple & Blackberry Pie then Apples.

    with regards
    Attached Files Attached Files
    Last edited by sipa; 10-29-2015 at 08:57 AM.

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Adapt this array formula to sort if possible

    Apologies. Missed a clause:

    =IFERROR(INDIRECT("Items!"&TEXT(MAX(IF(Items!$A$2:$K$60<>"",IF(COUNTIF(Items!$A$2:$K$60,"<"&Items!$A$2:$K$60)=SMALL(IF(Items!$A$2:$K$60<>"",COUNTIF(Items!$A$2:$K$60,"<"&Items!$A$2:$K$60)),ROWS($1:1)),10^5*ROW(Items!$A$2:$K$60)+COLUMN(Items!$A$2:$K$60)))),"R0C00000"),0),"")

    though I might disagree (and Excel certainly agrees with me!) that "Apples" precedes "Apple & Blackberry Pie" alphabetically.

    Regards

  5. #5
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Adapt this array formula to sort if possible

    Crikey !

    No apology necessary. I'm just very grateful for your help.
    Works perfectly now, thank you.
    Regards

  6. #6
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Adapt this array formula to sort if possible

    You're welcome!

    Cheers

  7. #7
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Adapt this array formula to sort if possible

    Having got that bit working, would it be possible to exclude certain items from the copy based on a list of locations, say freezer 1, freezer 3 etc ?

  8. #8
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Adapt this array formula to sort if possible

    Can you clarify? Where is this list of locations? In the actual worksheet? A Defined Name? Or to be entered in-formula?

    Regards

  9. #9
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Adapt this array formula to sort if possible

    A dynamic list in sheet Data, f2:f20

    thanks

  10. #10
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Adapt this array formula to sort if possible

    If the list of locations is in F2:F20, how do I relate them to the Items?

    Regards

  11. #11
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Adapt this array formula to sort if possible

    Sorry Brain freeze.... Lets reset.

    In my real workbook there is a sheet "Freezer Stocks" this holds a list of items in B4:b200 which is dynamic and random order . there is also a list of locations held in n4:n200 against each item, although some can be blank.

    hope that helps

  12. #12
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Adapt this array formula to sort if possible

    Thanks. And which of those do you wish to exclude?

    Perhaps you could re-post your workbook with this in mind to make things a touch easier?

    Regards

  13. #13
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Adapt this array formula to sort if possible

    Here is a new sample file, additional sheets.

    "freezer stocks" holds a random list of items and corresponding location.

    "Exclusions" holds a list of locations where items should be excluded from the sorted list.

    Thanks
    Attached Files Attached Files

  14. #14
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Adapt this array formula to sort if possible

    Ok, but things are getting a bit resource-heavy now...

    =IFERROR(INDIRECT("Items!"&TEXT(MAX(IF(Items!$A$2:$K$60<>"",IF(1-ISNUMBER(MATCH(INDEX('Freezer stocks'!$N$3:$N$115,N(IF(1,MATCH(Items!$A$2:$K$60,'Freezer stocks'!$B$3:$B$115,0)))),Exclusions!$F$2:$F$5,0)),IF(COUNTIF(Items!$A$2:$K$60,"<"&Items!$A$2:$K$60)=SMALL(IF(Items!$A$2:$K$60<>"",IF(1-ISNUMBER(MATCH(INDEX('Freezer stocks'!$N$3:$N$115,N(IF(1,MATCH(Items!$A$2:$K$60,'Freezer stocks'!$B$3:$B$115,0)))),Exclusions!$F$2:$F$5,0)),COUNTIF(Items!$A$2:$K$60,"<"&Items!$A$2:$K$60))),ROWS($1:1)),10^5*ROW(Items!$A$2:$K$60)+COLUMN(Items!$A$2:$K$60))))),"R0C00000"),0),"")

    Regards

  15. #15
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Adapt this array formula to sort if possible

    Xor LX

    Absolutely brilliant, your formula is working well in the sample sheet, now to test in the real sheet. I'll post back with any issues, but can't see there being any.

    As you say it's getting resource heavy, It does take a bit of time to recalculate, but that's not really an issue as the exclusions don't change very often.

    Thanks again & regards

  16. #16
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Adapt this array formula to sort if possible

    All good, thanks

  17. #17
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Adapt this array formula to sort if possible

    Great!

    Cheers.

+ 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. Need to auto sort tables or adapt formulas to fill cells based on values.
    By dropanddrive03 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-20-2013, 12:21 PM
  2. Sort data using array formula
    By mukeshbaviskar in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-15-2013, 06:36 PM
  3. Adapt Quicksort to Sort Two Arrays Simultaneously
    By RS15 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-18-2013, 03:56 PM
  4. [SOLVED] How to adapt 'sort' code to unprotect/protect worksheet
    By nje in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-19-2013, 03:11 PM
  5. Thinking maybe some sort of array formula?
    By aldridge_p in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2012, 11:00 AM
  6. Sort a Array Formula
    By Rhapsodie in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-28-2009, 04:41 PM
  7. how can i adapt this formula?
    By Gary Keramidas in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-15-2005, 04:05 PM
  8. [SOLVED] How to adapt a formula?
    By john.bedford3 in forum Excel General
    Replies: 2
    Last Post: 03-26-2005, 11: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