need help show all data in listbox on userform

Alaa mg

Active Member
Joined
May 29, 2021
Messages
343
Office Version
  1. 2019
hi
can any body convert show all columns insted of on column ,please? my data start from COL A: E so based on condition it just show one column A . i would show all of the columns in listbox when run the userform .
VBA Code:
Private Sub UserForm_Initialize()
Dim a, b, i As Long, x, y
With Sheets("sheet1")
    a = .Range("E1", .Range("E65536").End(xlUp)).Value
    b = .Range("A1", .Range("b65536").End(xlUp)).Value


End With

With Me.ListBox1

    For i = LBound(a) To UBound(a)
        If IsDate(a(i, 1)) Then
            x = DateSerial(Year(Date), Month(a(i, 1)), Day(a(i, 1)))
            'y = DateDiff("d", x, Date)
            If x >= Date Then
                .AddItem b(i, 1)
               
            End If
        End If
    Next
End With
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try the following...

VBA Code:
Private Sub UserForm_Initialize()

    Dim data As Variant
    With Sheets("sheet1")
        data = .Range("A1:E" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    End With
    
    Dim dt As Date
    Dim i As Long
    Dim j As Long
    With Me.ListBox1
        For i = LBound(data) To UBound(data)
            If IsDate(data(i, 5)) Then
                dt = data(i, 5)
                dt = DateSerial(Year(Date), Month(dt), Day(dt))
                If dt >= Date Then
                    .AddItem data(i, 1)
                    For j = 2 To .ColumnCount
                        .List(.ListCount - 1, j - 1) = data(i, j)
                    Next j
                End If
            End If
        Next
    End With
    
End Sub

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top