Check for empty ListBox row?

Hi,
When a user clicks on a button, I want to check if any rows in the ListBox contain data - if not - display a MsgBox.

My code below seems to be wrong somewhere - could someone please help.

//Loop through the rows. for iRow as integer = 0 to list.rowcount -1 if iRow = >1 then //No rows contain data so show message msgBox("test message") Exit end next next

Thank you all in advance.

I assume you meant to write:

      if iRow >= 1 then

Also:

    for iRow as integer = 0 to list.ListCount -1

But your entire loop could be reduced to:

if list.ListCount > 1 then MsgBox "test message"

So the test message will come up if you have more than one row in your ListBox, which seems opposite of what you asked. I feel like something is missing in my understanding here.

ListBox1.addrow "Apple" ListBox1.addrow "" ListBox1.addrow "pear" for i as integer = 0 to ListBox1.ListCount if ListBox1.ListCount = 0 or ListBox1.Cell(i,0) = "" then msgbox "empty row ! ("+str(i)+")" end if next i

I suppose you are after cells that contain nothing ?

This tests every cell column 0 for text. If a cell is empty, or if the listbox contains nothing, you get the message. You may try to scan columns over 0 for empty cells as well depending on your listbox configuration.

Thank you both very much - problem solved :slight_smile: