使用ComboBox时,代码运行正常,但使用ListBox时,即使选择了值,C变量也会设置为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
使用表格(“运营商”)。范围(“BG10:BG10000”)v = .value结束时使用CreateObject(“scripting.dictionary”)。comparemode = 1 For Each e in v if If .exists(e)然后。添加e,Nothing Next If .Count然后Me.ListBox8.List = Application.Transpose(.keys)End With
答案 0 :(得分:1)
这个小片段将解决错误:
If IsNull(ListBox8.Value) Then
C = ""
Else
C = CStr(ListBox8.Value)
End If