Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA - running scripting dictionary (error!)

Hi,

Following your advice, I am trying this code, in order to show item
listed in combobox only once each item. (like autofilter), but i
doesn't work, (it gives mi error: Variable not defined and remarkin
"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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VBA - running scripting dictionary (error!)

You need quotes around the "Scripting.Dictionary" in the
CreateObject function. E.g.,

Set Dic = CreateObject("Scripting.Dictionary")


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA - running scripting dictionary (error!)

You didn't follow my advice. My advice showed

Set Dic = CreateObject("Scripting.Dictionary")

You wrote

Set Dic = CreateObject(Scripting.Dictionary)

also
Dim Dic As New Scripting.Dictionary

shouldn't be used if you use late binding. You would use that for early
binding (creating a reference) and would not use the createobject line.

Dim dic as Object

for late binding

--
Regards,
Tom Ogilvy


"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/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default VBA - running scripting dictionary (error!)

shouldn't scripting.dictionary be a string: Set Dic = CreateObject("Scripting.Dictionary"


----- ajliaks wrote: ----

Hi

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


Private Sub UserForm_Initialize(

'Set a reference to MS Scripting runtim

Set Dic = CreateObject(Scripting.Dictionary

Dim Dic As New Scripting.Dictionar
Dim rSource As Range, cell As Rang
Dim sVal As Strin
Dim MyList As Strin

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

With ChapExpC
For Each cell In rSource.Cell
sVal = cell.Valu
If Not Dic.Exists(sVal) The
Dic.Add sVal, sVa
.AddItem sVa
End I
Nex
End Wit
Set Dic = Nothin

End Su

Thanks in advance


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


  #5   Report Post  
Posted to microsoft.public.excel.programming
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/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Div/0 error on running mean % ferde Excel Discussion (Misc queries) 2 October 4th 08 02:40 AM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
VBA question - Set reference to run Scripting.Dictionary ajliaks[_12_] Excel Programming 2 April 17th 04 03:47 PM
Running from web error Ken[_14_] Excel Programming 0 September 11th 03 06:47 PM


All times are GMT +1. The time now is 08:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"