Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 385
Default Unique Listbox Scripting Dictionary

I all,
Let me see if i can explain this in a way that will get some help!
I have a userform that has a combo box (A) that is filled when the form
initializes. Depending on what the user selects it then fills the next
combobox (B), my problem arises in that i just want the unique items. No
double entries to fill the combo box.
A B
Grapes Red Flames
Peach Yellow
Grapes Thompsons
Grapes Ruby Reds
Peach White

The following is some of the code:
Private Sub LoadLocation()

With lstFieldLocation
.Clear
Farm = cboFarm.Value
For Index = 2 To source.Rows.Count
If Farm = source.Cells(Index, 1) Then
.AddItem source.Cells(Index, 2) ' Field Location

End If
Next
End With

Dim Locations As New Scripting.Dictionary
For Index = 2 To source.Rows.Count
Loc = source.Cells(Index, "b").Value
If Not Locations.Exists(Loc) Then
Locations.Add Loc, Loc
lstFieldLocation.AddItem Farm
End If
Next
End Sub
Please let me know if you need anything else. Thank you so much, Jennifer
--
Thank you,

Jennifer
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Unique Listbox Scripting Dictionary

Private Sub LoadLocation()
Dim Farm, Index As Long, Loc
Dim Locations As Object

lstFieldLocation.Clear

Farm = cboFarm.Value

Set Locations = CreateObject("Scripting.Dictionary")
With Source
For Index = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
If .Cells(Index, "A").Value = Farm Then
Loc = .Cells(Index, "B").Value
If Not Locations.Exists(Loc) Then
Locations.Add Loc, Loc
lstFieldLocation.AddItem Loc
End If
End If
Next

End With
End Sub

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Jennifer" wrote in message
...
I all,
Let me see if i can explain this in a way that will get some help!
I have a userform that has a combo box (A) that is filled when the form
initializes. Depending on what the user selects it then fills the next
combobox (B), my problem arises in that i just want the unique items. No
double entries to fill the combo box.
A B
Grapes Red Flames
Peach Yellow
Grapes Thompsons
Grapes Ruby Reds
Peach White

The following is some of the code:
Private Sub LoadLocation()

With lstFieldLocation
.Clear
Farm = cboFarm.Value
For Index = 2 To source.Rows.Count
If Farm = source.Cells(Index, 1) Then
.AddItem source.Cells(Index, 2) ' Field Location

End If
Next
End With

Dim Locations As New Scripting.Dictionary
For Index = 2 To source.Rows.Count
Loc = source.Cells(Index, "b").Value
If Not Locations.Exists(Loc) Then
Locations.Add Loc, Loc
lstFieldLocation.AddItem Farm
End If
Next
End Sub
Please let me know if you need anything else. Thank you so much, Jennifer
--
Thank you,

Jennifer



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Unique Listbox Scripting Dictionary

Just some added information.
You asked for the scripting dictionary and Bob gave you that. It can also
be done with a built in collection object without the overhead of referencing
the scripting runtime:

Private Sub LoadLocation()
Dim Farm, Index As Long, Loc
Dim Locations As Collection

lstFieldLocation.Clear

Farm = cboFarm.Value

Set Locations = New collection
With Source
For Index = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
If .Cells(Index, "A").Value = Farm Then
Loc = .Cells(Index, "B").Value
On Error Resume Next
locations.Add loc, cstr(loc)
if err.Number = 0 then
lstFieldLocation.AddItem Loc
End If
On Error goto 0
End If
Next

End With
End Sub

--
Regards,
Tom Ogilvy


"Jennifer" wrote:

I all,
Let me see if i can explain this in a way that will get some help!
I have a userform that has a combo box (A) that is filled when the form
initializes. Depending on what the user selects it then fills the next
combobox (B), my problem arises in that i just want the unique items. No
double entries to fill the combo box.
A B
Grapes Red Flames
Peach Yellow
Grapes Thompsons
Grapes Ruby Reds
Peach White

The following is some of the code:
Private Sub LoadLocation()

With lstFieldLocation
.Clear
Farm = cboFarm.Value
For Index = 2 To source.Rows.Count
If Farm = source.Cells(Index, 1) Then
.AddItem source.Cells(Index, 2) ' Field Location

End If
Next
End With

Dim Locations As New Scripting.Dictionary
For Index = 2 To source.Rows.Count
Loc = source.Cells(Index, "b").Value
If Not Locations.Exists(Loc) Then
Locations.Add Loc, Loc
lstFieldLocation.AddItem Farm
End If
Next
End Sub
Please let me know if you need anything else. Thank you so much, Jennifer
--
Thank you,

Jennifer

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
Collection VS Scripting.Dictionary Tetsuya Oguma Excel Programming 1 October 16th 06 09:49 AM
Scripting.Dictionary question Jennifer Excel Programming 6 October 12th 06 07:30 PM
Scripting.Dictionary Jennifer Excel Programming 2 October 12th 06 12:03 PM
VBA - running scripting dictionary (error!) ajliaks[_13_] Excel Programming 4 April 18th 04 10:13 PM
VBA question - Set reference to run Scripting.Dictionary ajliaks[_12_] Excel Programming 2 April 17th 04 03:47 PM


All times are GMT +1. The time now is 05:21 AM.

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"