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.


[TABLE="width: 431"]
<tbody>[TR]
[TD]Rep[/TD]
[TD]Weekly Hours[/TD]
[TD]Capacity How many hours left?[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD="align: right"]38[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]Mary[/TD]
[TD="align: right"]37[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]Sue[/TD]
[TD="align: right"]39[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD="align: right"]40[/TD]
[TD="align: right"]0[/TD]
[/TR]
</tbody>[/TABLE]



My second table has stores each rep can drive to.


[TABLE="width: 267"]
<tbody>[TR]
[TD]Rep[/TD]
[TD]Store Number[/TD]
[TD]Miles Away[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"]85[/TD]
[/TR]
[TR]
[TD]Mary[/TD]
[TD="align: right"]27[/TD]
[TD="align: right"]91[/TD]
[/TR]
[TR]
[TD]Sue[/TD]
[TD="align: right"]40[/TD]
[TD="align: right"]45[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD="align: right"]34[/TD]
[TD="align: right"]31[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]55[/TD]
[/TR]
[TR]
[TD]Mary[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]55[/TD]
[/TR]
[TR]
[TD]Sue[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]99[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD="align: right"]32[/TD]
[TD="align: right"]21[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]13[/TD]
[/TR]
[TR]
[TD]Mary[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]98[/TD]
[/TR]
[TR]
[TD]Sue[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]58[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD="align: right"]45[/TD]
[TD="align: right"]99[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]28[/TD]
[/TR]
[TR]
[TD]Mary[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]90[/TD]
[/TR]
[TR]
[TD]Sue[/TD]
[TD="align: right"]42[/TD]
[TD="align: right"]49[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD="align: right"]42[/TD]
[TD="align: right"]55[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]30[/TD]
[/TR]
[TR]
[TD]Mary[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]30[/TD]
[/TR]
[TR]
[TD]Sue[/TD]
[TD="align: right"]25[/TD]
[TD="align: right"]63[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]99[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD="align: right"]22[/TD]
[TD="align: right"]95[/TD]
[/TR]
[TR]
[TD]Mary[/TD]
[TD="align: right"]47[/TD]
[TD="align: right"]76[/TD]
[/TR]
[TR]
[TD]Sue[/TD]
[TD="align: right"]44[/TD]
[TD="align: right"]56[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD="align: right"]48[/TD]
[TD="align: right"]33[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD="align: right"]50[/TD]
[TD="align: right"]56[/TD]
[/TR]
[TR]
[TD]Mary[/TD]
[TD="align: right"]50[/TD]
[TD="align: right"]26[/TD]
[/TR]
[TR]
[TD]Sue[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]64[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD="align: right"]23[/TD]
[TD="align: right"]100[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD="align: right"]14[/TD]
[TD="align: right"]71[/TD]
[/TR]
[TR]
[TD]Mary[/TD]
[TD="align: right"]38[/TD]
[TD="align: right"]32[/TD]
[/TR]
[TR]
[TD]Sue[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD="align: right"]37[/TD]
[TD="align: right"]79[/TD]
[/TR]
</tbody>[/TABLE]

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

[TABLE="width: 267"]
<tbody>[TR]
[TD]Rep[/TD]
[TD]Store Number[/TD]
[TD]Miles Away[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]13[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]28[/TD]
[/TR]
</tbody>[/TABLE]

thanks for any help provided.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
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,223,741
Messages
6,174,230
Members
452,553
Latest member
red83

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