So up until now I've managed to piece together solutions from questions others have asked. I am very new to VBA but to date I have always been able to figure it out... until now. I'm really hoping someone here can give me some guidance. I tried copying a range into a listbox but I could only get 1 match to show. I then tried to individually fill each matching cell to each listbox item. Unsuccessful at both.
What I'm trying to do:
I have a 7 column non-varying data source for personal expenses. I'm trying to match 2 criteria 1. mnth = December and 2. if there's any non blank item in column 7 or "G".
If those 2 criteria match, I want that row to be inserted into listbox1. Here is what I have attempted and doesn't work:
[VBA]
Private Sub UserForm_Initialize()
Dim ws1 As Worksheet
Dim k As Integer
Dim lstrow As Long
Set ws1 = ThisWorkbook.Sheets("Expenses")
lstrow = ws1.Cells(ws1.Rows.Count, 8).End(xlUp).Row
mnth = "December"
With Me.ListBox1
ListBox1.Clear
ListBox1.ColumnCount = 7
End With
For k = 2 To lstrow
If ws1.Cells(k, 8).Value = mnth And ws1.Cells(k, 7).Value <> vbNullString Then
ListBox1.AddItem ws1.Cells(k, 2).Value 'Sheets("expenses").Range("B" & k, "H" & k).Value
ListBox1.List(k - 2, 1) = ws1.Cells(k, 3)
ListBox1.List(k - 2, 2) = ws1.Cells(k, 4)
ListBox1.List(k - 2, 3) = ws1.Cells(k, 5)
ListBox1.List(k - 2, 4) = ws1.Cells(k, 6)
ListBox1.List(k - 2, 5) = ws1.Cells(k, 7)
ListBox1.List(k - 2, 6) = ws1.Cells(k,
End If
Next k
End Sub
[/VBA]
I appreciate anyone's help with this. Thanks in advance!