|
楼主 |
发表于 2024-8-23 09:23
|
显示全部楼层
谢谢解答,再做一遍题
- Function delBetweenStation(Sht As Worksheet, StationStr)
- Dim StationArr, DistArr
- Dim Str, Str1, Dist As Integer, Dist1
- Dim Rng As Range
- 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
- Rr = 10
- For ii = 0 To UBound(StationArr)
- If StationStr = StationArr(ii) Then
- Exit For
- End If
- Next ii
-
- ''
- 'For ii = Kk To Kk 'UBound(StationArr)
-
- Str1 = StationArr(ii) & "→"
- Dist = 0 'DistArr(ii)
- Str = Str1 & Str1
- For jj = ii + 1 To UBound(StationArr)
- ''
- Str = Str1 & StationArr(jj)
- Dist = Dist + DistArr(jj)
- With Sht
- .Cells(Rr, 1) = Rr - 9
- .Cells(Rr, 2) = Str
- .Cells(Rr, 3) = Dist
- Select Case Dist
- Case Is = 0
- .Cells(Rr, 4) = "-"
- Case Is <= 4000
- .Cells(Rr, 4) = 2
- Case Is <= 8000
- .Cells(Rr, 4) = 3
- Case Is <= 12000
- .Cells(Rr, 4) = 4
- Case Is <= 18000
- .Cells(Rr, 4) = 5
- Case Is <= 24000
- .Cells(Rr, 4) = 6
- Case Is <= 32000
- .Cells(Rr, 4) = 7
- Case Is <= 40000
- .Cells(Rr, 4) = 8
- Case Else
- End Select
- End With
- Rr = Rr + 1
- Next jj
- 'Next ii
- ''
- Set Rng = Sht.Cells(10, 1).CurrentRegion
- Set Rng = Rng(, 1).Resize(Rng.Rows.Count, 1)
- Debug.Print Rng.Address
- 'Str = "=" & """各站点有""" & """ & " & " & """ & Rng.Address(0, 0) & """ & " & " & """ & "个组合" & """"
- Str = "=" & """统计共"" & " & " Count(" & Rng.Address(0, 0) & ")" & " & " & """站点" & """"
- Debug.Print Str
- Sht.Cells(1, 2) = Str
- End Function
- Function BetweenStation(Sht As Worksheet, StationStr)
- Dim StationArr, DistArr
- Dim Str, Str1, Dist As Integer, Dist1
- Dim eastArr(), westArr()
- Dim Rng As Range
- StationArr = Array("陈官营", "深安大桥南", "兰州城市学院", "兰州海关", "马滩", "土门墩", "兰州西站北广场", "西站什字", "七里河", "小西湖", "文化宫", "西关", "省政府", "东方红广场", "兰州大学", "五里铺", "省气象局", "携星墩", "焦家湾", "东岗")
- Debug.Print UBound(StationArr)
-
- 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(1)
- Rr = 0
- For ii = 0 To UBound(StationArr)
- If StationStr = StationArr(ii) Then
- ReDim westArr(ii - 1, 3)
- ReDim eastArr(UBound(DistArr) - ii - 1, 3)
- Exit For
- End If
- Next ii
-
- Str1 = StationArr(ii) & "→"
- Dist = 0 'DistArr(ii)
- ''
- For jj = ii + 1 To UBound(StationArr)
- ''
- Str = Str1 & StationArr(jj)
- Dist = Dist + DistArr(jj)
- With Sht
- eastArr(Rr, 0) = Rr + 1
- eastArr(Rr, 1) = Str
- eastArr(Rr, 2) = Dist
- Select Case Dist
- Case Is = 0
- eastArr(Rr, 3) = "-"
- Case Is <= 4000
- eastArr(Rr, 3) = 2
- Case Is <= 8000
- eastArr(Rr, 3) = 3
- Case Is <= 12000
- eastArr(Rr, 3) = 4
- Case Is <= 18000
- eastArr(Rr, 3) = 5
- Case Is <= 24000
- eastArr(Rr, 3) = 6
- Case Is <= 32000
- eastArr(Rr, 3) = 7
- Case Is <= 40000
- eastArr(Rr, 3) = 8
- Case Else
- End Select
- End With
- Rr = Rr + 1
- Next jj
- '''
- Rr = 0
- For jj = ii - 1 To 0 Step -1
- ''
- Str = Str1 & StationArr(jj)
- Dist = Dist + DistArr(jj)
- With Sht
- westArr(Rr, 0) = Rr + 1
- westArr(Rr, 1) = Str
- westArr(Rr, 2) = Dist
- Select Case Dist
- Case Is = 0
- westArr(Rr, 3) = "-"
- Case Is <= 4000
- westArr(Rr, 3) = 2
- Case Is <= 8000
- westArr(Rr, 3) = 3
- Case Is <= 12000
- westArr(Rr, 3) = 4
- Case Is <= 18000
- westArr(Rr, 3) = 5
- Case Is <= 24000
- westArr(Rr, 3) = 6
- Case Is <= 32000
- westArr(Rr, 3) = 7
- Case Is <= 40000
- westArr(Rr, 3) = 8
- Case Else
- End Select
- End With
- Rr = Rr + 1
- Next jj
- Arr(0) = eastArr
- Arr(1) = westArr
- BetweenStation = Arr
- End Function
- Sub llll()
- Dim Sht As Worksheet
- Dim Rng As Range
- Dim Rr
- Rr = 10
- Set Sht = Sheet2
- Sht.Cells.Clear
- 'BetweenStation "兰州海关"
-
- 'BetweenStation Sht, "西站什字"
- 'BetweenStation Sht, "省政府"
- 'BetweenStation Sht, "陈官营"
- Arr = BetweenStation(Sht, "携星墩")
-
-
- With Sht
- .Cells(Rr - 2, 1) = "陈官营方向" & UBound(Arr(0)) + 1 & "个站点"
- .Cells(Rr, 1).Resize(UBound(Arr(0)) + 1, 4) = Arr(0)
- .Cells(Rr - 2, 6) = "东岗方向" & UBound(Arr(1)) + 1 & "个站点"
- .Cells(Rr, 6).Resize(UBound(Arr(1)) + 1, 4) = Arr(1)
- End With
- End Sub
复制代码
现在的问题是从陈官营出发遇到的问题是
ii=0时 ii - 1不成立。
For ii = 0 To UBound(StationArr)
If StationStr = StationArr(ii) Then
ReDim westArr(ii - 1, 3)
ReDim eastArr(UBound(DistArr) - ii - 1, 3)
Exit For
End If
Next ii
|
|