Sorting with a formularised column

Peter Davison

Board Regular
Joined
Jun 4, 2020
Messages
165
Office Version
  1. 365
Platform
  1. Windows
I have a list of products Column C which has come from a different sheet (Pivot Top Sellers) based on a group name in Column B.
Using the code below it provides me a list of products that are specific to just that group.

Excel Formula:
=IFERROR(INDEX('Pivot Top Sellers'!C:C, SMALL(IF((Dashboard!$CE$10='Pivot Top Sellers'!B:B), MATCH(ROW('Pivot Top Sellers'!B:B), ROW('Pivot Top Sellers'!B:B)), ""),ROWS($A$1:A1))),"-")

Where this final data is in a separate worksheet (Dashboard) there are various other columns next to the products, which I would like to sort on.
Because the formula above brings the data in as a list in the order of the sheet where it gets the info from, when I sort it, it does not change the products order.
Is there any other ways to bring in the products so they can be sorted?

Any help would be appreciated.
 
Last edited by a moderator:

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,480
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
On what basis do you want to bring the data in then? In other words, how does it relate to the adjacent columns?
 

Peter Davison

Board Regular
Joined
Jun 4, 2020
Messages
165
Office Version
  1. 365
Platform
  1. Windows
I have the Group as a user selection from a user drop down box, so the formula goes and looks for the user selection in a separate worksheet and with the code sent previously finds all the products that relate to that group and lists them in a column.
Once it has listed all the products the columns to the right of the products are sales and ranking columns which I want to sort the list of products on. To get all the sales data I use SUMIfs formulas using the product name to search from a another separate worksheet with all the sales on.

Hope that helps a little.
 

Peter Davison

Board Regular
Joined
Jun 4, 2020
Messages
165
Office Version
  1. 365
Platform
  1. Windows
Just on your post code XL2BB.
I tried to add in that option but it doesn't appear in the list of add on's
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,400
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

=IFERROR(INDEX('Pivot Top Sellers'!C:C, SMALL(IF((Dashboard!$CE$10='Pivot Top Sellers'!B:B), MATCH(ROW('Pivot Top Sellers'!B:B), ROW('Pivot Top Sellers'!B:B)), ""),ROWS($A$1:A1))),"-")

Where this final data is in a separate worksheet (Dashboard)
If that means that the quoted formula is on the Dashboard sheet, then you don't need the Dashboard! reference for cells/ranges on that sheet. Further, doing so can cause exactly this type of problem with sorting. There is a simple example here to demonstrate the issue.

So, if the formula is on Dashboard then the first thing I would try is removing that Dashboard! from the formula
Excel Formula:
=IFERROR(INDEX('Pivot Top Sellers'!C:C, SMALL(IF(($CE$10='Pivot Top Sellers'!B:B), MATCH(ROW('Pivot Top Sellers'!B:B), ROW('Pivot Top Sellers'!B:B)), ""),ROWS($A$1:A1))),"-")
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,400
Office Version
  1. 365
Platform
  1. Windows
A couple more suggestions
- That formula makes my test workbook very sluggish - because you are referencing whole columns. Surely you are not using a million+ rows? Try restricting the column row ranges if possible.

- Since you have Excel 365 you (should) have some new functions that can make this job much simpler. If you have the FILTER function then try this (check row range is sufficient for your data) in a single cell. The other results should automatically 'spill' down the column.

Excel Formula:
=FILTER('Pivot Top Sellers'!C1:C1000,'Pivot Top Sellers'!B1:B1000=$CE$10,"")
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,480
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS

ADVERTISEMENT

The issue is that your formula is actually sorting the results it returns. If you can replace the ROWS($A$1:A1) part with hardcoded row numbers, then the sorting should work. Alternatively, depending where the sales and ranking data comes from, perhaps you should be using a pivot table and a slicer to select the Group.
 

Peter Davison

Board Regular
Joined
Jun 4, 2020
Messages
165
Office Version
  1. 365
Platform
  1. Windows
I tried the first example removing the word Sheet Name "Dashboard", but that didn't change anything with the sort the list still stayed the same order after the sort.
I then used the filter option and when I went to sort it says I cannot sort on an array.
Any other thoughts?
Thanks for all your help so far.
 

Peter Davison

Board Regular
Joined
Jun 4, 2020
Messages
165
Office Version
  1. 365
Platform
  1. Windows
Hi RoryA
I tried taking away the hard coding but it didn't work on the sort. Looked like it was going to but then it reverted back to the original list.
The data comes from a large list so I don't know where each product will be in the list hence it looks for the group then selects each line in the group.
I'm going to a meeting now, but if you have any other thoughts that would be great.
I could do the pivot but it would then mean doing a pivot every time a new group was selected.
Thank you so far for your help.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,480
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
You only need one pivot - you simply filter it for whichever group you need.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,784
Messages
5,626,850
Members
416,205
Latest member
rondon

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
Top