PDA

View Full Version : VBA -how to get every second row?



kubek
10-16-2008, 02:44 PM
hi, a couple of days ago i have fount this great example of list like that:


vbaexpress.com/kb/getarticle.php?kb id=532

i tried many things to make the listbox show me every second row, but without any result. can somebody help me to reach my goal? thanks in advance

GTO
10-17-2008, 04:01 AM
Greetings kubeck,

The article you found uses .RowSource to load the ListBox's three columns. As RowSource is a contiguous range of cells, I don't see any way of only 'loading' every other row. Rather, you could use a loop to go thru a range and pick up every other row...

How about the code, or better yet, a sample workbook. There are some very helpful folks here, but you need to provide a tad bit more. This was akin to, "Read about this car here, and please build me a different model..."

Mark

mdmackillop
10-17-2008, 05:32 AM
With Sheets(1)
Set rng = .Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
For i = 1 To rng.Cells.Count
If i Mod 2 = 1 Then
.ListBox1.AddItem rng(i)
End If
Next
End With