Skipping blank cells in a column...

G

Guest

I have a column where some data is dumped. Sometimes there is a blank cell in
a column. I want to add the values to the listbox from only those cells where
there is a data. If there is no data i need to skip the cell.

I am using the following code...which works fine if there are no blanks in
between or start ....but it doesn't work fine for where there are blank in
between or start

Suggestions will be highly appreciated.

Set TestSheet = ThisWorkbook.Sheets("Test")

TopicCount = Application.WorksheetFunction.CountA(TestSheet.Range("3:3"))
For Col = 2 To TopicCount + 1
lstbox1.AddItem TestSheet.Cells(3, Col)
Next Col
lstbox1.ListIndex = 0
 
T

Tom Ogilvy

Dim rng as Range, Testsheet as Worksheet
Set TestSheet = ThisWorkbook.Sheets("Test")
With TestSheet
set rng = .Range(.Cells(3,1),.Cells(3,256).End(xltoLeft))
End With
For each cell in rng
if not isempty(cell) then
lstbox1.AddItem cell.Value
Next
lstbox1.ListIndex = 0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top