按照一定的规则复制,订购和分组数据(创build运输服务单)

每天我都要订购一个客户列表,并将他们列入几种运输服务中。 所以从机场到他们预订的酒店。

这里是一个链接到名为“chegadas”的工作表的示例文件。 https://www.dropbox.com/s/xlcj9o1le44b2my/Transporte%20do%20aeroporto.xls?dl=1

过程如下:

1-按列VOO从A到Z的顺序(这是到达飞行数据)

2-按酒店区分组(在“酒店信息”表)

3-组直到8人(最大容量)

4-创build机场(起点)和每项服务的酒店之间的最短路线。

表“chegadas-2”有一个步骤1到3的例子。

对于第四步,我想创build一个距离matrix(如在“distâncias”表 – 缺less一些酒店)。 并使用像这样的解决scheme: https : //www.youtube.com/watch?v=-E3rSoClgMI

我知道我可以按照“Chegadas TD”这个表的forms将它们分组几小时,但是我仍然需要用8人分开,然后再排列最佳路线。

这是可能的Excel中自动使用VBA和/或公式? 先谢谢你!!!

1,是的,寻找最适合你的自动filtersorting代码seq。 IE:

With ThisWorkbook.ActiveSheet .Range("A1").AutoFilter Field:=1, Criteria1:="<>" .Range("A1").CurrentRegion.Sort Key1:=.Range("A1"), Order1:=xlAscending, _ Header:=xlYes, OrderCustom:=1, DataOption1:=xlSortNormal End With 

2,3。最佳做法是不要在表单中使用空格,尝试重命名“hoteis_info”,这里最好的办法可能是将特定列中的独特组作为横向标题,然后遍历VOO列中的人员同时计算是否有超过8个。例如:

 Sub GroupbyHotel() 'assuming VOO is in Col 1 'assuming Hotel is in Col 2 Dim ColVOO As Long: ColVOO = 1 Dim ColHoteis As Long: ColHoteis = 2 Dim PaxName As String Dim CounterPax As Long Dim PaxInVehicle As Long Dim FoundHoteis As Range Dim RangeUnique As Range Const SheetHoteis = "hoteis_info" Const SheetARRIVAL_FLIGHT = "ARRIVAL_FLIGHT" Sheets(SheetARRIVAL_FLIGHT).Columns(ColHoteis).Copy Destination:=Sheets(SheetHoteis).Range("A1") With Sheets(SheetHoteis) ' 1. With Sheets(SheetHoteis) Set RangeUnique = .Range("A1:A" & .Cells(Rows.Count, "A").End(xlUp).Row) RangeUnique.RemoveDuplicates Columns:=1, Header:=xlNo RangeUnique.Copy .Range("B1").PasteSpecial Paste:=xlPasteAll, Transpose:=True Application.CutCopyMode = False .Columns("A:A").Clear End With ' 1. With Sheets(SheetHoteis) With Sheets(SheetARRIVAL_FLIGHT) ' 2. With Sheets(SheetARRIVAL_FLIGHT) For CounterPax = 1 To .Cells(Rows.Count, ColVOO).End(xlUp).Row PaxName = .Cells(CounterPax, ColVOO).Value Set FoundHoteis = Sheets(SheetHoteis).Rows(1).Find(What:=.Cells(CounterPax, ColHoteis).Value) With Sheets(SheetHoteis) ' 3. With Sheets(SheetHoteis) PaxInVehicle = .Cells(Rows.Count, FoundHoteis.Column).End(xlUp).Row If PaxInVehicle Mod 9 = 0 Then ' 1. If Mod PaxInVehicle Mod 9 = 0 'this works to assign 8 passengers per vehicle (9th row would be the blank divisor) .Cells(.Cells(Rows.Count, FoundHoteis.Column).End(xlUp).Row + 2, FoundHoteis.Column).Value = PaxName '+2 to leave the blank among car assignments Else ' 1. If Mod PaxInVehicle Mod 9 = 0 .Cells(.Cells(Rows.Count, FoundHoteis.Column).End(xlUp).Row + 1, FoundHoteis.Column).Value = PaxName End If ' 1. If Mod PaxInVehicle Mod 9 = 0 End With ' 3. With Sheets(SheetHoteis) Next CounterPax End With ' 2. With Sheets(SheetARRIVAL_FLIGHT) End Sub 

这就是所谓的“最短path” 。 你需要更多的研究,并理解其背后的逻辑。 一旦你完成了这些,你可以继续为它制定一个子集,或者到Solver加载项那里去做。
这是我build议的工作stream模型。

我想你可能需要使用某种VLOOKUP来比较和计算最短的路线。

http://excelcount.com/howto/how-do-i-retrieve-the-second-occurrence-with-vlookup/