Formula to pick stores with lowest miles?

bbrimberry

New Member
Joined
Mar 23, 2016
Messages
34
Hello,

I am hopeful someone will be able to help me with the problem outlined below.

I have 2 tables. One table has sales reps and the number of hours in a week they work.


RepWeekly HoursCapacity How many hours left?
John382
Mary373
Sue391
Bob400

<tbody>
</tbody>



My second table has stores each rep can drive to.


RepStore NumberMiles Away
John1885
Mary2791
Sue4045
Bob3431
John555
Mary255
Sue699
Bob3221
John113
Mary1298
Sue1158
Bob4599
John1128
Mary190
Sue4249
Bob4255
John430
Mary530
Sue2563
Bob1599
John2295
Mary4776
Sue4456
Bob4833
John5056
Mary5026
Sue764
Bob23100
John1471
Mary3832
Sue1310
Bob3779

<tbody>
</tbody>

I need to get excel to return the stores that are within each reps capacity of 40 hours.

I would like excel to somehow return the stores with the least number of miles.


if we used rep john as an example john has 2 hours left.
lets also assume that each store is 1 hour of work.
so i would like exel to return the 2 rows below as the answer

RepStore NumberMiles Away
John113
John1128

<tbody>
</tbody>

thanks for any help provided.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
thanks for the reply. i would like to stop when the hours = 40. each store in the table is 1 hour. so for john i want to return the closest 2 stores
 
Upvote 0
A single formula and pivot table can do this:


Excel 2010
ABCDEFGHI
1RepWeekly HoursCapacity How many hours left?RepStore NumberMiles AwayIndex
2John382John18850
3Mary373Mary27910
4Sue391Sue40450
5Bob400Bob34310
6John5550
7RepIndexStore NumberMiles AwayMary2550
8John2113Sue6990
9John51128Bob32210
10Mary45026John1132
11Mary6530Mary12980
12Mary93832Sue11580
13Sue11310Bob45990
14John11285
15Mary1900
16Sue42490
17Bob42550
18John4300
19Mary5306
20Sue25630
21Bob15990
22John22950
23Mary47760
24Sue44560
25Bob48330
26John50560
27Mary50264
28Sue7640
29Bob231000
30John14710
31Mary38329
32Sue13101
33Bob37790
Sheet7 (2)
Cell Formulas
RangeFormula
I2{=IFERROR(IF(H2<=SMALL(IF($F$2:$F$33=F2,$H$2:$H$33),VLOOKUP(F2,$A$2:$C$5,3,0)),RANK(H2,$H$2:$H$33,1),0),0)}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,454
Messages
6,124,933
Members
449,195
Latest member
Stevenciu

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