Dear all
Below code to colour listview items in date range. I have an excel form and it has a Sheet called DATA. On the DATA sheet Column C I have various dates I am comparing these dates with Today's date and if they are different range I want them colour differently on the listview. The below code is giving error on the red highlighted line
Do you know why?
Kind regards
This is the code
Below code to colour listview items in date range. I have an excel form and it has a Sheet called DATA. On the DATA sheet Column C I have various dates I am comparing these dates with Today's date and if they are different range I want them colour differently on the listview. The below code is giving error on the red highlighted line
Do you know why?
Kind regards
This is the code
Code:
Private Sub FormatListView1()
Dim Item As ListItem
Dim Counter As Long
Dim Tarih As Date
' Set the variable to the ListItem.
For Counter = 1 To Me.ListView1.ListItems.Count
Set Item = Me.ListView1.ListItems.Item(Counter)
' Set the variable to the Freight
Note = Item.SubItems(17)
[COLOR="#FF0000"]Tarih = Sheets("DATA").Range("C2:C2000")[/COLOR]
With Me.ListView1
If Tarih = Today Then
For n = 1 To 17
.ListItems.Item(Counter).ForeColor = vbYellow
.ListItems.Item(Counter).ListSubItems(n).ForeColor = vbYellow
Next n
Else
If Date - Tarih > 30 Then
For n = 1 To 17
.ListItems.Item(Counter).ForeColor = vbRed
.ListItems.Item(Counter).ListSubItems(n).ForeColor = vbRed
Next n
Else
If Date - Tarih < 30 Then
For n = 1 To 17
.ListItems.Item(Counter).ForeColor = vbGreen
.ListItems.Item(Counter).ListSubItems(n).ForeColor = vbGreen
Next n
Else
If Tarih = "" Then
For n = 1 To 17
.ListItems.Item(Counter).ForeColor = vbBlue
.ListItems.Item(Counter).ListSubItems(n).ForeColor = vbBlue
Next n
End If
End If
End If
End If
End With
Next Counter
Me.ListView1.Refresh
End Sub
Last edited: