Dear all
I have an excel user form whish has a ListView , all the Listview data comes from excel sheet. What I m trying to do is colour code the list view item.
I have Note column which is SubItems(17) and contains notes
I have "Tarih" Column which is on Sheets("DATA") Column A and contains Dates
If Note is not blank and Tarih = Today then ListView item colour is Magenta
If Note is not blank and Tarih not equal to Today and Tarih-Today difference greater than 30 then ListView item colour is Red
If Note is not blank and Tarih not equal to Today and Tarih-Today difference less than 30 then ListView item colour is Green
If Note is Blank then ListView item colour Blue
but below code doesn't work, can you please let me know what I am missing. I cant put sample data as some of the info comes from the server.
Kind regards
I have an excel user form whish has a ListView , all the Listview data comes from excel sheet. What I m trying to do is colour code the list view item.
I have Note column which is SubItems(17) and contains notes
I have "Tarih" Column which is on Sheets("DATA") Column A and contains Dates
If Note is not blank and Tarih = Today then ListView item colour is Magenta
If Note is not blank and Tarih not equal to Today and Tarih-Today difference greater than 30 then ListView item colour is Red
If Note is not blank and Tarih not equal to Today and Tarih-Today difference less than 30 then ListView item colour is Green
If Note is Blank then ListView item colour Blue
but below code doesn't work, can you please let me know what I am missing. I cant put sample data as some of the info comes from the server.
Code:
Private Sub FormatListView1()
Dim Item As ListItem
Dim Counter As Long
Dim Note As String
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").Cells(1 + Counter, 3)
With Me.ListView1
If Note <> "" And Tarih = Today Then
For n = 1 To 17
.ListItems.Item(Counter).ForeColor = vbMagenta
.ListItems.Item(Counter).ListSubItems(n).ForeColor = vbMagenta
Next n
Else
If Note <> "" And Today <> Tarih And Today - Tarih > 30 Then
For n = 1 To 17
.ListItems.Item(Counter).ForeColor = vbRed
.ListItems.Item(Counter).ListSubItems(n).ForeColor = vbRed
Next n
Else
If Note <> "" And Today <> Tarih And Today - Tarih < 30 Then
For n = 1 To 17
.ListItems.Item(Counter).ForeColor = vbGreen
.ListItems.Item(Counter).ListSubItems(n).ForeColor = vbGreen
Next n
Else
If Note = "" 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
Kind regards