My listview is on a userform. When I execute my code, it changes the color of all entries in the listview. I want it to change only the current entry. E.g.; If the entries are all black (not dupes) and I add an entry that is a dupe and change the forecolor to blue, all preceeding entries become blue as well. Here is my code:
Private Sub addtolv() Dim dupe As Boolean Dim li As ListItem' note: RecordNumber writecolumn and LASTROW are globals dupe = False With ListView1' check if already in columnm If Application.WorksheetFunction.CountIf(Range(ThisWorkbook.writecolumn & "2:" & ThisWorkbook.writecolumn & CStr(LASTROW)), Range("B" & RecordNumber)) = 0 Then .ForeColor = vbBlack Else dupe = True .ForeColor = vbBlue End If Set li = .ListItems.Add(, Worksheets("Sheet2").Range("B" & RecordNumber), Worksheets("Sheet2").Range("A" & RecordNumber), 0) li.SubItems(1) = Worksheets("Sheet2").Range("B" & RecordNumber) li.SubItems(2) = Worksheets("Sheet2").Range("C" & RecordNumber) li.SubItems(3) = Worksheets("Sheet2").Range("D" & RecordNumber) li.SubItems(4) = Worksheets("Sheet2").Range("E" & RecordNumber) li.SubItems(5) = RecordNumber End WithEnd Sub
After setting li, I have tried setting the forecolor using li.ForeColor but that didn't change the colors at all.