Need urgent help with vba code

bmrsalgas

New Member
Joined
Aug 11, 2017
Messages
26
Hi.

I have this code for populating a listview box that works almost perfectly...

What I want here, is to the listview box returns the data filtered by the content of the TextBox1


Code:
Private Sub UserForm_Initialize()

Dim Item As ListItem
Dim LinhaFinal As Integer
Dim i As Integer


    Sheets("JOBDATA").Select
    ActiveSheet.ListObjects("JOBDATA").Range.AutoFilter Field:=10, Criteria1:="LCZ"
    TextBox1.Text = Sheet5.Cells(5, 14)
    
With ListView1
    .Gridlines = False
    .View = lvwReport
    .FullRowSelect = True
    .ColumnHeaders.Add Text:="Created Date", Width:=80
     .ColumnHeaders.Add Text:="Booking Date", Width:=80
    .ColumnHeaders.Add Text:="Job Number", Width:=80
    .ColumnHeaders.Add Text:="Consigment ID", Width:=80
    .ColumnHeaders.Add Text:="Shipper", Width:=80
    .ColumnHeaders.Add Text:="Origin Country", Width:=80
    .ColumnHeaders.Add Text:="Destination Country", Width:=80
    .ColumnHeaders.Add Text:="Total Units", Width:=80
    .ColumnHeaders.Add Text:="Volume (cu/m)", Width:=80
    .ColumnHeaders.Add Text:="Weight (kg)", Width:=80
     
End With


ListView1.ListItems.Clear


LinhaFinal = Sheet2.Cells(Rows.Count, 50).End(xlUp).Row


For i = 2 To LinhaFinal


    If Sheet5.Cells(5, 14).Value = TextBox1.Text Then
        Set Item = ListView1.ListItems.Add(, , Sheet5.Cells(5, 14))
                Item.SubItems(1) = Sheet2.Cells(i, 51)
                Item.SubItems(2) = Sheet2.Cells(i, 52)
                Item.SubItems(3) = Sheet2.Cells(i, 53)
                Item.SubItems(4) = Sheet2.Cells(i, 54)
                Item.SubItems(5) = Sheet2.Cells(i, 55)
                Item.SubItems(6) = Sheet2.Cells(i, 56)
                Item.SubItems(7) = Sheet2.Cells(i, 57)
                Item.SubItems(8) = Sheet2.Cells(i, 58)
                Item.SubItems(9) = Sheet2.Cells(i, 59)
    End If
    
Next
  
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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