Banner

Saturday, March 25, 2017

Display Monthly Transaction Listbox From Worksheet Excell VBA





Private Sub UserForm_Initialize()
Me.ComboBox1.Value = Format(Date, "YYYY")
Me.ComboBox2.Value = Format(Date, "MMMM")
For a = 0 To 5
Me.ComboBox1.AddItem Format(Date, "YYYY") - a
Next a
For b = 0 To 11
c = Application.WorksheetFunction.EoMonth _
("1" & "/" & "January" & "/" & Me.ComboBox1.Value, b)
Me.ComboBox2.AddItem Format(c, "MMMM")
Next b
End Sub

Me.ListBox1.Selected(0) = True
For i = 2 To Application.WorksheetFunction.CountA(Sheet1.Range("A:A"))
b = Application.WorksheetFunction.EDate _
("1" & "/" & Me.ComboBox2.Value & "/" & Me.ComboBox1.Value, 0)
c = Application.WorksheetFunction.EoMonth _
("1" & "/" & Me.ComboBox2.Value & "/" & Me.ComboBox1.Value, 0)
If Sheet1.Cells(i, 1).Value >= CDate(b) And Sheet1.Cells(i, 1).Value <= CDate(c) Then
Me.ListBox1.AddItem Sheet1.Cells(i, 1).Value
For d = 1 To 4
Me.ListBox1.List(ListBox1.ListCount - 1, d) = Sheet1.Cells(i, d + 1).Value & ".00"
Next d
End If
Next i
End Sub

2 comments:

  1. I am a novice in excel vba and I appreciate your youtube tutorial.
    when I dupricate your code in the tutorial "Display Monthly Transaction in Listbox from Worksheet Userform Excel VBA"
    I have a runtime error message with error code '2147467259 (80004005)' in the line "me.Listbox1.clear (2nd line of Private Sub ComboBox2_Change().
    Will you give me your advice to remove the error?
    archie.ishikawa@gmail.com

    ReplyDelete
  2. dear
    how can Download your file

    ReplyDelete

Please do not enter any spam message in comment box