Sort results of Index/Match array formula OR VBA to paste values

JonHaywood

New Member
Joined
Jul 23, 2014
Messages
34
I'm using an Index/Match array formula to pull out results from a data table (based on three search criteria). The formula works great, except that it populates the results in the same order as the data table - I want to sort them based on another category.

My data table is on Sheet 1...
ABCD
1T/LLocationDateDescription
2A PersonKanban01/06/14Text1
3A PersonStores02/06/14Text2
402/06/14Text3
5B GoodKanban02/06/14Text4
6A PersonKanban03/06/14Text5
7C ClearlyKanban03/06/14Text6
8B GoodCarousel04/06/14Text7
9C ClearlyStores05/06/14Text8

<tbody>
</tbody>

(Note: The blank cells in A4 and B4 are deliberate)

I don't want users to have access to this main data table, but I do want different users to be able to select some search criteria, then view a summary of their data. I've created a summary table on Sheet 2...
ABC
1T/L(Dropdown list of names)
2Date From(date)
3Date To(date)
4
5LocationDateDescription
6
7
8
9
10
11

<tbody>
</tbody>

The search criteria are entered by the user in cells B1 to B3.

In A6 (then copied across and down) I have the formula...

{=IF(ROWS(A$6:A6)<=(SUMPRODUCT(--(Sheet1!$A$2:$A$9=$B$1),--(Sheet1!$C$2:$C$9>=$B$2),--(Sheet1!$C$2:$C$9<=($B$3+0.999)))),INDEX(Sheet1!B$2:B$9,SMALL(IF((Sheet1!$A$2:$A$9=$B$1)*(Sheet1!$C$2:$C$9>=$B$2)*(Sheet1!$C$2:$C$9<=($B$3+0.999)),ROW(Sheet1!B$2:B$9)-ROW(Sheet1!B$2)+1),ROWS(A$6:A6))),"")}

So, if B1 = A Person, B2 = 01/06/14 and B3 = 03/06/14 the results I get are...
ABC
5LocationDateDescription
6Kanban01/06/14Text1
7Stores02/06/14Text2
8Kanban03/06/14Text5
9

<tbody>
</tbody>

Is there a way to sort these results by location? I've tried all basic ways to sort them but no joy. I have looked at other posts where Autofilter has been suggested, but my VBA knowledge is weak and I can't figure out how to change any of the suggestions to fit my tables.

Alternatively, I'd be happy if there was a VBA routine to automatically copy and paste the values into another table which could be filtered and sorted by the user, but again, I can't figure out how to adapt the examples I've seen of this approach.

Help me Mr Excel forum... you're my only hope!!!

Thanks
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi,

Perhaps this array formula** in A6 (I've removed your inclusion of +0.999 since I could not see its purpose, though kindly explain and/or re-insert it. I've also amended the SUMPRODUCT to a SUM since the use of the former in an array formula is somewhat tautological):

=IF(ROWS(A$6:A6)<=SUM((Sheet1!$A$2:$A$9=$B$1)*(Sheet1!$C$2:$C$9>=$B$2)*(Sheet1!$C$2:$C$9<=$B$3)),INDEX(Sheet1!B$2:B$9,MATCH(SMALL(IF(Sheet1!$A$2:$A$9=$B$1,IF(Sheet1!$C$2:$C$9>=$B$2,IF(Sheet1!$C$2:$C$9<=$B$3,COUNTIF(Sheet1!$B$2:$B$9,"<"&Sheet1!$B$2:$B$9)+ROW(Sheet1!$B$2:$B$9)/10^9))),ROWS(A$6:A6)),COUNTIF(Sheet1!$B$2:$B$9,"<"&Sheet1!$B$2:$B$9)+ROW(Sheet1!$B$2:$B$9)/10^9,0)),"")

Copy down and across as required.

Incidentally, it's more efficient to have the first clause of the IF statement in a separate cell somewhere, e.g. in D1:

=SUMPRODUCT(--(Sheet1!$A$2:$A$9=$B$1),--(Sheet1!$C$2:$C$9>=$B$2),--(Sheet1!$C$2:$C$9<=$B$3))


and then the beginning of the formula becomes:

=IF(ROWS(A$6:A6)<=$D$1,INDEX(...


etc., and each instance of the formula does not have to perform this initial calculation again.

Regards
 
Upvote 0
Wow, thank you - it works a treat!!

If I'm seeing it right, the SMALL function brings the results out in order based on the figure created by the COUNTIF + the row number divided by 10^9. It's ingenious!

FYI, I included the +0.999 because the date field in my actual data also contains a timestamp (I simplified the data for posting); adding 0.999 includes the entries made on the same date as the 'Date To' criterion.

Also, the original version of the formula I adapted had the SUMPRODUCT in a 'helper cell'... I thought I was being clever by incorporating it into a sinlge formula!!! Lesson learnt there!

Thanks so much for taking time to help me.
 
Upvote 0
Glad I could help and thanks for the clarification re the +0.999 - makes good sense now!

Cheers!
 
Upvote 0

Forum statistics

Threads
1,215,427
Messages
6,124,830
Members
449,190
Latest member
rscraig11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top