【发布时间】:2017-03-31 20:12:10
【问题描述】:
使用 ComboBox 时,代码运行良好,但使用 ListBox 时,即使选择了一个值,C 变量也会设置为 null。我收到一条错误消息“无效使用 Null”。
我需要一个 ListBox,因为我需要从下拉列表中选择多个值。
任何帮助都将不胜感激,因为我在一天中的大部分时间都在为此苦苦思索。
Public Sub CommandButton1_Click()
Dim C As String
Dim LastTarget As range
Dim LastTarget2 As range
Set LastTarget = ActiveCell
Set LastTarget2 = ActiveCell.Offset(0, 3)
Set wb1 = Workbooks("Premium Billing Report TemplateListBox.xlsm")
'LastRow = wb1.Sheets("CGIBill").range("A:A").Find("Overall - Total", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
C = ListBox8.value
'For i = 11 To LastRow
'Counts & Coverages based on plan code selection
LastTarget = Application.CountIf(wb1.Sheets("Carrier").range("BG:BG"), C)
LastTarget2 = Application.SumProduct(Application.SumIf(wb1.Sheets("Carrier").range("BG:BG"), C, wb1.Sheets("Carrier").range("BK:BK")))
'Next
Unload Me
End Sub
With Sheets("Carrier").range("BG10:BG10000") v = .value End With CreateObject("scripting.dictionary") .comparemode = 1 For Each e In v If Not .exists(e) Then .Add e, Nothing Next If .Count Then Me.ListBox8.List = Application.Transpose(.keys) End With
【问题讨论】:
-
代码填充 ListBox8...
-
With Sheets("Carrier").range("BG10:BG10000") v = .value End With CreateObject("scripting.dictionary") .comparemode = 1 For Each e In v If Not .exists(e) Then .Add e, Nothing Next If .Count Then Me.ListBox8.List = Application.Transpose(.keys) End With
-
使用编辑将其放入原始帖子中。
标签: excel listbox userform vba