-
VBA -how to get every second row?
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
-
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
-
[vba]
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
[/vba]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules