這可能與scripting.dictionary
從範圍中排除空白嗎? 我正在使用此代碼從範圍中查找特殊值。我不需要excel公式範圍,但在VBA解決方案(如果存在)。VBA - scripting.dictionary exlude blank
有了這個代碼,我在列表框總是一個空白項。
Dim v, e
With Sheets("DATA").Range("NAMED_RANGE")
v = .Value
End With
With CreateObject("scripting.dictionary")
.CompareMode = 1
For Each e In v
If Not .Exists(e) Then .Add e, Nothing
Next
If .Count Then Me.TextBox121.List = Application.Transpose(.keys)
ThisWorkbook.Worksheets("DICTIONARY").Range("B2").Resize(UBound(.keys), 1).Value = _
Application.Transpose(.keys)
End With
添加如果e.Value <> 「」 然後檢查如果不.Exists(E)......之前 –
'如果不.Exists(E)和E <> vbNullString然後。新增E, Nothing'作爲@ShaiRado所述 – R3uK
@ R3uK這從你代碼工作,但如果範圍只有一個值有錯誤(「應用程序定義或deffined對象錯誤」) – Nataniell