Hi!
Currently Im using this code to read my excel cell values into my listview control and to change change the color on my listview rows.
Here's my question: How do I design my loop not to add rows when column G has a value?
I have tried with the following code
But I cannot get it to work? Any tips on this?
Currently Im using this code to read my excel cell values into my listview control and to change change the color on my listview rows.
Here's my question: How do I design my loop not to add rows when column G has a value?
I have tried with the following code
Code:
If lvwItem.SubItems(6) = "" Then
lvwItem.SubItems(3).Remove (2)
End If
But I cannot get it to work? Any tips on this?
Code:
Dim ws As Worksheet
Dim lngRow As Long
Dim lvwItem As ListItem
Dim lngEndCol As Long
Dim lngCol As Long
Dim lngEndRow As Long
Dim lngItemIndex As Long
Dim lvwItem2 As ListItem
Set ws = Worksheets("Ärenden")
lngEndCol = ws.Range("A1:K1").End(xlToRight).Column
lngEndRow = ws.Range("A1:K1").End(xlDown).Row
lngRow = 1
With ListView1
.View = lvwReport
For lngCol = 1 To lngEndCol
.ColumnHeaders.Add , , ws.Cells(lngRow, lngCol).Value
Next
For lngRow = 2 To lngEndRow
lngCol = 1
lngItemIndex = 0
Set lvwItem = .ListItems.Add(, , ws.Cells(lngRow, lngCol).Value)
For lngCol = 2 To lngEndCol
lngItemIndex = lngItemIndex + 1
If lvwItem.SubItems(3) = "21 Försäkringskassan" Then
GoTo apa
Else
lvwItem.SubItems(lngItemIndex) = ws.Cells(lngRow, lngCol).Value 'Adds Value from Current Row and Column 1
End If
apa:
If lvwItem.SubItems(3) = "22 Kronofogden" Then
lvwItem.ForeColor = RGB(100, 200, 50)
lvwItem.ListSubItems.Item(lngItemIndex - 2).ForeColor = RGB(100, 200, 50)
ElseIf lvwItem.SubItems(3) = "26 CSN" Then
lvwItem.ForeColor = RGB(255, 165, 0)
lvwItem.ListSubItems.Item(lngItemIndex - 2).ForeColor = RGB(255, 165, 0)
ElseIf lvwItem.SubItems(3) = "21 Försäkringskassan" Then
lvwItem.ForeColor = RGB(255, 0, 0)
lvwItem.ListSubItems.Item(lngItemIndex - 2).ForeColor = RGB(255, 0, 0)
End If
' Set lvwItem2 = .ListItems.Remove(lngItemIndex)
' .ListItem.Remove(lngItemIndex).Value
lvwItem.SubItems(lngItemIndex) = ws.Cells(lngRow, lngCol).Value
'End If
Next
Next
End With