Dmitry_D_Onishchenko
New Member
- Joined
- Nov 27, 2019
- Messages
- 18
- Office Version
- 365
- 2013
- 2010
- Platform
- Windows
Hi all,
I have a UserForm with a ComboBox and a ListBox on it; their respective names are "ComboBox_Field" and "ListBox_Value". Their list values are currently strings, but might be dates or integers as well.
Now, I have a function to count the number of selected items in a ListBox:
For a reason unknown to me, I can't pass my ListBox to ListBoxSelectionCount() due to variable type mismatch:
However, if I redefine the function and pass the argument as Variant instead of ListBox
, everything works fine.
My question is: Why is the result of VarType(ListBox_Value) equal to vbNull? (I would expect this to be identical to my Combobox properties - I have VarType(ComboBox_Field)=8 as the ComboBox is populated with strings.)
Thanks in advance,
Dmitry
I have a UserForm with a ComboBox and a ListBox on it; their respective names are "ComboBox_Field" and "ListBox_Value". Their list values are currently strings, but might be dates or integers as well.
Now, I have a function to count the number of selected items in a ListBox:
VBA Code:
Function ListBoxSelectionCount(LB As ListBox) As Long
Dim x As Long, count As Long
For x = 0 To (LB.ListCount - 1)
If LB.Selected(x) Then count = count + 1
Next x
ListBoxSelectionCount = count
End Function
For a reason unknown to me, I can't pass my ListBox to ListBoxSelectionCount() due to variable type mismatch:
Code:
Debug.Print VarType(ListBox_Value) ' returns 1 as for vbNull data type
However, if I redefine the function and pass the argument as Variant instead of ListBox
VBA Code:
Function ListBoxSelectionCount(LB As Variant) As Long
' exactly the same code as above
End Function
My question is: Why is the result of VarType(ListBox_Value) equal to vbNull? (I would expect this to be identical to my Combobox properties - I have VarType(ComboBox_Field)=8 as the ComboBox is populated with strings.)
Thanks in advance,
Dmitry