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

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
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,215,465
Messages
6,124,977
Members
449,200
Latest member
Jamil ahmed

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