为什么我的 ListBox8.value 列为 Null?
Why is my ListBox8.value listed as Null?
当使用 ComboBox 时,代码运行良好,但当使用 ListBox 时,C 变量被设置为 null,即使值是 selected。我收到一条错误消息 "Invalid use of Null"。
我需要一个 ListBox,因为我需要 select 下拉列表中的多个值。
任何帮助将不胜感激我一天中的大部分时间都在为此苦思冥想。
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 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) 结束于
这个小片段将解决错误:
If IsNull(ListBox8.Value) Then
C = ""
Else
C = CStr(ListBox8.Value)
End If
当使用 ComboBox 时,代码运行良好,但当使用 ListBox 时,C 变量被设置为 null,即使值是 selected。我收到一条错误消息 "Invalid use of Null"。
我需要一个 ListBox,因为我需要 select 下拉列表中的多个值。
任何帮助将不胜感激我一天中的大部分时间都在为此苦思冥想。
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 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) 结束于
这个小片段将解决错误:
If IsNull(ListBox8.Value) Then
C = ""
Else
C = CStr(ListBox8.Value)
End If