View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis[_3_] Dana DeLouis[_3_] is offline
external usenet poster
 
Posts: 690
Default VBA - running scripting dictionary (error!)

As a side note...

MyList = "P3:P20"
Set rSource = Range("MyList")


You may get an error here. If so, see if this will work without the quotes.

MyList = "P3:P20"
Set rSource = Range(MyList)

If Not Dic.Exists(sVal) Then


Usually, it is not necessary to test for Existence first. I find it easier
to use an "On error" as in this simple example...

On Error Resume Next
For Each cell In rSource.Cells
sVal = cell.Value
Dic.Add sVal, sVal
Next

Just some ideas. HTH. :)
--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"ajliaks " wrote in message
...
Hi,

Following your advice, I am trying this code, in order to show items
listed in combobox only once each item. (like autofilter), but it
doesn't work, (it gives mi error: Variable not defined and remarking
"Scripting")


Private Sub UserForm_Initialize()

'Set a reference to MS Scripting runtime

Set Dic = CreateObject(Scripting.Dictionary)

Dim Dic As New Scripting.Dictionary
Dim rSource As Range, cell As Range
Dim sVal As String
Dim MyList As String

'Point to specific column
MyList = "P3:P20"
Set rSource = Range("MyList")

With ChapExpCB
For Each cell In rSource.Cells
sVal = cell.Value
If Not Dic.Exists(sVal) Then
Dic.Add sVal, sVal
AddItem sVal
End If
Next
End With
Set Dic = Nothing

End Sub

Thanks in advance.


---
Message posted from http://www.ExcelForum.com/