Filter ListView

Gilang

New Member
Joined
Feb 21, 2021
Messages
48
Office Version
  1. 2007
Platform
  1. Windows
I tried to display the data by filtering cells(i,17)>0, the data was filtered successfully but the display in the listview is not as expected. there is an empty row in the list view.
please enlighten me, thanks in advance.
this my code:

Private Sub CommandButton1_Click()
Set ws = Sheets("DfPinj")
On Error Resume Next
ws.Range("B1").Select
Dim ch As ColumnHeader
Dim lngRow As Long
Dim ListItem As MSComctlLib.ListItem

Dim ItemList As ListItem

Dim n As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False

SetCommonListViewProperties LstData

With LstData.ColumnHeaders
Set ch = .Add(, , ws.Cells(1, 2), 75, lvwColumnLeft)
Set ch = .Add(, , ws.Cells(1, 3), 70, lvwColumnCenter)
Set ch = .Add(, , ws.Cells(1, 4), 150, lvwColumnLeft)
Set ch = .Add(, , ws.Cells(1, 5), 150, lvwColumnLeft)
Set ch = .Add(, , ws.Cells(1, 6), 95, lvwColumnCenter)
Set ch = .Add(, , ws.Cells(1, 7), 80, lvwColumnCenter)
Set ch = .Add(, , ws.Cells(1, 8), 100, lvwColumnLeft)
Set ch = .Add(, , ws.Cells(1, 9), 100, lvwColumnLeft)
Set ch = .Add(, , "JK WKT", 50, lvwColumnCenter)
Set ch = .Add(, , "JENIS PINJ", 70, lvwColumnLeft)
Set ch = .Add(, , "BGA", 30, lvwColumnRight)
Set ch = .Add(, , ws.Cells(1, 13), 70, lvwColumnLeft)
Set ch = .Add(, , ws.Cells(1, 14), 70, lvwColumnLeft)
Set ch = .Add(, , ws.Cells(1, 15), 150, lvwColumnLeft)
Set ch = .Add(, , ws.Cells(1, 16), 80, lvwColumnRight)
Set ch = .Add(, , ws.Cells(1, 17), 70, lvwColumnRight)
Set ch = .Add(, , ws.Cells(1, 18), 80, lvwColumnRight)
Set ch = .Add(, , "Late Pym", 50, lvwColumnRight)
End With

Dim rngData As Range
Dim RowCount As Long
Dim colCount As Long
Dim LstItem
Dim j As Long

Set rngData = ws.Range("B2").CurrentRegion

RowCount = rngData.Rows.Count
colCount = rngData.Columns.Count
ws.Activate

Set ItemList = Me.LstData.ListItems.Add

With LstData
.ListItems.Clear

For i = 2 To RowCount
Set ListItem = .ListItems.Add(Text:=rngData(i, 1).Value)
For j = 2 To colCount
If ws.Cells(i, 17) > 0 Then
If j = 16 Then
ListItem.ListSubItems.Add Text:=Format(rngData(i, j).Value, "#,##0")
ElseIf j = 15 Or j = 17 Then
ListItem.ListSubItems.Add Text:=Format(rngData(i, j).Value, "dd-mmm-yy")
Else
ListItem.ListSubItems.Add Text:=rngData(i, j).Value
End If
End If
Next j
Next i
End With
End Sub


Please correct my code
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    28.4 KB · Views: 26

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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