Ramazan Topal
New Member
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)
Tarih = Sheets("DATA").Range("C2:C2000")
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
Above 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 and I am comparing these dates with today's date and if they are in different range I like them colour differently on the listview. The code is giving an error on this line
Tarih = Sheets("DATA").Range("C2:C2000")
Do you know why?
Kind regards
Edit : moved to appropriate VBA forum !
Last edited by a moderator: