I'm working on an Excel project where I have a VBA UserForm with two ListBox controls. I load them by assigning an array to the List property. All of the expected data shows up, except for the seventh column which is entirely blank.
Why is this entire column blank?
Additional details:
The array has around 15 columns and 25 rows.
The seventh column of the array is listed in Locals as type Variant/Decimal. It contains UPC values (up to 14 digits) stored in the database as DECIMAL(14,0).
None of the UPC values are NULL or blank. They DO show up in the array in the Locals window and they can be retrieved from the ListBox, just not seen.
The ListBox has ListStyle fmListStylePlain and MultiSelect fmMultiSelectMulti.
Although you cannot Dim (declare) a variable as Decimal, you can convert to Decimal with the CDec function: ?typename(CDec(4.5))
in the Immediate window.
Minimal Example:
Create a UserForm with a ListBox (Listbox1), two TextBox controls (TextBox1 and TextBox2), and two Command Buttons (CommandButton1 and CommandButton2).
In the Code Module of the UserForm, paste in the below code:
Private Sub CommandButton1_Click()
Dim x(0 To 0, 0 To 0)
x(0, 0) = CDec(TextBox1.Text)
ListBox1.List = x
TextBox2.Text = ListBox1.List(0, 0)
End Sub
Private Sub CommandButton2_Click()
Dim x(0 To 0, 0 To 0)
x(0, 0) = CDbl(TextBox1.Text)
ListBox1.List = x
TextBox2.Text = ListBox1.List(0, 0)
End Sub
Run the UserForm, type a number (with or without decimal places) in TextBox1, then click CommandButton1. ListBox1 remains blank, but Textbox2 shows a value.
Click CommandButton2. ListBox1 and TextBox2 show the value.
?FormName.ListBoxName.List(0,13)
). Does it return a value or nothing? This will indicate if the data is making it into the List – DavidN