0
我想製作一個消除行上空白單元格的列表框。在列A
我有一些單元格包含數據和一些是空白的。我無法刪除空行,因爲在其他列中它們包含數據。如何在listbox
中製作非空白單元格rowsource
?消除列表框行中的空白單元格來源
我想製作一個消除行上空白單元格的列表框。在列A
我有一些單元格包含數據和一些是空白的。我無法刪除空行,因爲在其他列中它們包含數據。如何在listbox
中製作非空白單元格rowsource
?消除列表框行中的空白單元格來源
怎麼樣一個循環,檢查是否存在在每個單元格的值:
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
大編輯@Wolfie。謝謝! –
@wolfie:ActiveSheet.UsedRange.Rows.Count包括計數中的空單元嗎? –
是的,'UsedRange'可能有點溫情,因爲它有時會「記住」比您現在使用的更大的範圍!然而,它從「A1」(假設第1行中的某個單元格和第A列中的某個單元格曾經有過任何內容)到右下角常用單元格。玩了一圈,並在這裏看到更多:http://stackoverflow.com/questions/7423022/getting-the-actual-usedrange – Wolfie