mperrah
09-11-2015, 11:22 AM
I have a listbox (lbBills) with 3 columns and several rows.
I have a 6x7 array matrix of listboxes named dcell1 to dcel42
all on one userform (ufCal)
My lbBills has the day number in 3rd column.
I'm trying to fill the dcell# listbox with the 1st and 2nd column
if the 3rd column matches the dcell#
the D1 is the first day of month so I add that to line up days and values.
if tuesday is first of month D1 = 3 so dcell3 gets 1st of month values
Not sure where I am going wrong here.
Sub insertBills_uf()
Dim c, r, D1, DL As Long
Dim MyDate As Date
With ufCal
MyDate = CDate(.uMonth.Caption & "/1/" & .uYear.Caption)
D1 = FirstWeekDayOfMonth(MyDate) - 1
DL = DaysInMonth(MyDate)
For c = 1 To DL
For r = 0 To .lbBills.ListCount - 1
If .lbBills.List(r, 2) = c Then
If .Controls("dcell" & D1 + c).Value = "" Then
.Controls("dcell" & D1 + c).Value = .lbBills.List(r, 0) & " - " & .lbBills.List(r, 1)
Else
.Controls("dcell" & D1 + c).Value = .Controls("dcell" & D1 + c).Value & vbLf & _
.lbBills.List(r, 0) & " - " & .lbBills.List(r, 1)
End If
End If
Next r
Next c
End With
End Sub
I have a 6x7 array matrix of listboxes named dcell1 to dcel42
all on one userform (ufCal)
My lbBills has the day number in 3rd column.
I'm trying to fill the dcell# listbox with the 1st and 2nd column
if the 3rd column matches the dcell#
the D1 is the first day of month so I add that to line up days and values.
if tuesday is first of month D1 = 3 so dcell3 gets 1st of month values
Not sure where I am going wrong here.
Sub insertBills_uf()
Dim c, r, D1, DL As Long
Dim MyDate As Date
With ufCal
MyDate = CDate(.uMonth.Caption & "/1/" & .uYear.Caption)
D1 = FirstWeekDayOfMonth(MyDate) - 1
DL = DaysInMonth(MyDate)
For c = 1 To DL
For r = 0 To .lbBills.ListCount - 1
If .lbBills.List(r, 2) = c Then
If .Controls("dcell" & D1 + c).Value = "" Then
.Controls("dcell" & D1 + c).Value = .lbBills.List(r, 0) & " - " & .lbBills.List(r, 1)
Else
.Controls("dcell" & D1 + c).Value = .Controls("dcell" & D1 + c).Value & vbLf & _
.lbBills.List(r, 0) & " - " & .lbBills.List(r, 1)
End If
End If
Next r
Next c
End With
End Sub