数据源
StationArr = Array("陈官营", "深安大桥南", "兰州城市学院", "兰州海关", "马滩", "土门墩", "兰州西站北广场", "西站什字", "七里河", "小西湖", "文化宫", "西关", "省政府", "东方红广场", "兰州大学", "五里铺", "省气象局", "携星墩", "焦家湾", "东岗")
DistArr = Array(0, 1579, 2340, 955, 2073, 2007, 907, 1614, 1060, 1376, 890, 1066, 969, 1456, 1426, 1293, 1303, 1163, 1116, 933)
- Sub dffdsaf()
- 'Arr = BetweenStation("兰州城市学院", "文化宫")
- Arr = BetweenStation("兰州大学", "兰州城市学院")
- ''
- Dim Sht As Worksheet, Rng As Range
- Set Sht = Application.ActiveSheet
- With Sheet4
- .Cells.Clear
- .Cells.Font.Size = 9
- Set Rng = .Cells(5, 2)
- End With
- With Application.WorksheetFunction
- Rng.Resize(3, UBound(Arr)) = .Transpose(Arr)
- End With
- End Sub
- Function BetweenStation(StationA, StationB)
- StationArr = Array("陈官营", "奥体中心", "兰州城市学院", "兰州海关", "马滩", "土门墩", "兰州西站北广场", "西站什字", "七里河", "小西湖", "文化宫", "西关", "省政府", "东方红广场", "兰州大学", "五里铺", "省气象局", "携星墩", "焦家湾", "东岗")
- ''
- DistArr = Array(0, 1579, 2340, 955, 2073, 2007, 907, 1614, 1060, 1376, 890, 1066, 969, 1456, 1426, 1293, 1303, 1163, 1116, 933)
- Dim Rr As Integer, Kk
- Dim Arr()
- 'Dim StationA, StationB
- Dim Kk1, Kk2
- Dim Dist As Integer
- For ii = 0 To UBound(StationArr)
- If StationA = StationArr(ii) Then
- Kk1 = ii
- End If
- ''
- If StationB = StationArr(ii) Then
- Kk2 = ii
- End If
- Next ii
- ''
- If Kk1 < Kk2 Then
- ReDim Arr(Kk2 - Kk2 - 1, 2)
- For ii = Kk1 To Kk2
- Debug.Print StationArr(ii)
-
- Next ii
- ElseIf Kk1 > Kk2 Then
- ReDim Arr(Kk1 - Kk2 - 0, 2)
-
- For ii = Kk1 To Kk2 Step -1
- Arr(Kk1 - ii, 0) = StationArr(ii)
- ''
- If ii = Kk1 Then
- Dist = 0
- Else
- Dist = Dist + DistArr(ii)
- End If
- ''
- Arr(Kk1 - ii, 1) = Dist
- Arr(Kk1 - ii, 2) = retuDist(Dist)
-
- Next ii
- End If
- BetweenStation = Arr
-
- End Function
- Function retuDist(Dist As Integer)
- Select Case Dist
- Case Is = 0
- retuDist = "-"
- Case Is <= 4000
- retuDist = 2
- Case Is <= 8000
- retuDist = 3
- Case Is <= 12000
- retuDist = 4
- Case Is <= 18000
- retuDist = 5
- Case Is <= 24000
- retuDist = 6
- Case Is <= 32000
- retuDist = 7
- Case Is <= 40000
- retuDist = 8
- Case Else
- End Select
- End Function
复制代码
结果
|