Colouring the listview item by date age

lapot

New Member
Joined
Jul 25, 2014
Messages
30
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

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:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,215,586
Messages
6,125,689
Members
449,250
Latest member
azur3

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