Code:
Option Explicit
Private Sub Form_Load()
'add Cols
Dim i As Long, j As Long
For i = 1 To 5
With ListView1.ColumnHeaders.Add
.Text = "C" & i
.Width = ListView1.Width \ 5
End With
With ListView2.ColumnHeaders.Add
.Text = "C" & i
.Width = ListView1.Width \ 5
End With
Next
'add same data to both LVs
For i = 1 To 5
With ListView1.ListItems.Add
.Text = "R" & i & " C1"
For j = 1 To 4
.SubItems(j) = "R" & i & "C" & j + 1
Next
End With
With ListView2.ListItems.Add
.Text = "R" & i & "C1"
For j = 1 To 4
.SubItems(j) = "R" & i & "C" & j + 1
Next
End With
Next
End Sub
'Here we expect all items in LV1 to be deleted
'since they have the same data as LV2
Private Sub Command1_Click()
Dim i As Long
'when removing LV items, always step backwards
For i = ListView1.ListItems.Count To 1 Step -1
With ListView1.ListItems(i)
If .SubItems(4) = ListView2.ListItems(i).SubItems(4) Then
ListView1.ListItems.Remove i
End If
End With
Next
End Sub