【发布时间】:2016-05-13 09:32:10
【问题描述】:
我正在尝试根据在下拉菜单中选择的路由代码填充端口列表。下拉列表在 BASE_RouteCode ('Schedule Tool'!$F$8) 范围内,路由代码存储在动态范围 RouteCodes (=Routes!$B$2:INDEX(Routes!$B$2:$B$27, COUNTA(Routes!$B$2:$B$27))) 中,端口列表存储在沿着 RoutePorts (=Routes!$B$2:INDEX(Routes!$B$2:$AZ$27, COUNTA(Routes!$B$2:$AZ$27))) 中每个路由代码的行。
目的是让 BASE_RouteCode 的每一次更改都会触发填充端口列表的子程序;目前我已经拼凑起来作为一个快速的尝试。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Range("BASE_RouteCode")
Call PopulatePortList
End Sub
Sub PopulatePortList()
Dim iCol As Integer, iRow As Integer
If IsNumeric(WorksheetFunction.Match(Range("BASE_RouteCode").Value, Range("Routecodes"), 0)) Then
iRow = WorksheetFunction.Match(Range("BASE_RouteCode").Value, Range("Routecodes"), 0) + 1
' Testing code
MsgBox "Row number for route " & Range("BASE_RouteCode").Value & " is " & iRow
Worksheets("Schedule Tool").Cells(8, 9).Value = iRow
' FOR ... WHILE loop (through iCol values) to populate list goes here
Else
MsgBox "Please select a valid route code."
End If
End Sub
但是,当我更改下拉列表值时,会出现短暂的闪烁,但没有明显发生任何事情,也没有触发代码中的断点。
问号:
- 我不确定 KeyCells 是否应该与 Target 相同;那 是从我在其他地方找到的示例中复制的,但似乎都没有 工作。
- 如果我尝试手动运行 PopulatePortList,我会得到 1004 进入IF子句时出错。
我哪里错了?
【问题讨论】: