I am trying to create a listbox that would be visible on the worksheet that would display data that fall into certain condition.
Firstly, I am trying to get the headers to be named in the listbox: wondering if I could do that directly somehow using an array or explicitly naming the header somehow (if that is possible).
Secondly, I have two columns of data I would like to present in the listbox showing the value for two cells in the same row. "Serial Number" and "Date to Review". I am having trouble with my If statement in this particular instance, I am returning all serial numbers.
Private Sub loadreviewdates()
Dim listdata2 As MSForms.ListBox, tabledata As ListObject, xl As Range
Set listdata2 = Sheet1.Reviewdates
Set tabledata = Sheet2.ListObjects("Table2")
With listdata2
.AutoLoad = True
.Clear
.ColumnHeads = True
.ColumnCount = 2
End With
For Each xl In tabledata.ListColumns("Days to Review").DataBodyRange
If xl.Value > 0 Then
listdata2.AddItem xl.Offset(, -20).Value
listdata2.AddItem xl.Offset(, -1).Value
End If
Next
End Sub
This is an image of the listbox I have: ListBox Basically, If my row of data had a certain 'upcoming date' due to review a Serial Number's case; I would like the serial number shown in column 1 and the review date on column 2.
I use the If condition in a countdown (in number of days) in a separate column, if there is no review date the countdown would be blank, if there is a review date, the countdown number of days would be more than 0 and hopefully would show in my list box.
Fairly new to VBA and coding in general, would appreciate any advice or help.