PDA

View Full Version : How to load specific items to the listview 6.0



Nader
03-21-2008, 07:37 AM
I have a microsoft control lisview 6.0
And I use this way to load the items in the sheets1 to the listview


For i = 10 To Sheets(1).UsedRange.Rows.Count
Set itmAdd = ListView1.ListItems.Add(Text:= Sheets(1).Range("A" & i).Value)
itmAdd.SubItems(1) = Sheets(1).Range("B" & i).Value


I want a code to load only the item with this condition

If cells(i,1).value= S and cells(i,2).value= 7

Load the item in blue ..as it show in the pic

Erdin? E. Ka
03-21-2008, 10:29 AM
Hi Nader, i was tried the codes below for help to you, but there is an error returning...


Dim i As Integer
Dim Sht As Worksheet
Dim xlLastUsedRow As Long
Set Sht = Worksheets("sheets1")
Sht.Activate
xlLastUsedRow = Sht.Cells.SpecialCells(xlCellTypeLastCell).Row
On Error Resume Next
ListView1.ListItems.Clear
On Error GoTo 0
ListView1.View = lvwReport
For i = 1 To xlLastUsedRow
If Sht.Cells(i, 1) = "S" And Sht.Cells(i, 2) = 7 Then
With ListView1
.ListItems.Add , , Sht.Cells(i, 1)
With .ListItems(i)
.SubItems(1) = Sht.Cells(i, 2)
.SubItems(2) = Sht.Cells(i, 3)
.SubItems(3) = Sht.Cells(i, 4)
.SubItems(4) = Sht.Cells(i, 5)
.SubItems(5) = Sht.Cells(i, 6)
.SubItems(6) = Sht.Cells(i, 7)
.SubItems(7) = Sht.Cells(i, 8)
End With
End With
End If
Next i

Run-time error: '35600'
Index of of bounds

Then i clicked to debug:
the yellow row is:
With .ListItems(i)

There should be a mistake in my codes... :think:

Nader
03-21-2008, 12:31 PM
Any way thank you for your effort