首页 文章

消除listbox rowsource中的空白单元格

提问于
浏览
0

我正在尝试创建一个消除行上空白单元格的列表框 . 在 A 列中,我有一些包含数据的单元格和一些空白的单元格 . 我无法删除空行,因为在其他列中它们包含数据 . 如何在 listbox 中将非空单元格设为 rowsource

1 回答

  • 1

    如何检查每个单元格中是否有值的循环:

    Dim CountLng as Long
    
    'Set CountLng to maximum row in column A that you would like to search for.
    'This example uses the number of rows in the entire used range of the worksheet
    
    CountLng = ActiveSheet.UsedRange.Rows.Count
    
    With listbox1
    
        ' Loop over each cell in the column A 
        For x = 1 To CountLng
    
            ' If the cell is not blank then add it as a list item
            If ActiveSheet.Range("A" & x).Value <> "" Then
    
                .AddItem ActiveSheet.Range("A" & x).Value
    
            End If
    
        Next x
    
    End With
    

相关问题