Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default An easy one: Help with some VB funct about list and filter

I belive it's very simple what i'm tryng to accomplish, but I dont have the
functions:

Columns/Rows a b c d e f
1 si
2 so
3 si
4 si
5
6 su
7 sr
8 d
9
10 as
in a array ( and so on in my combobox) should appear ap1(si,so,su,sr,d,as)
tnks in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default An easy one: Help with some VB funct about list and filter

Here is some fairly generic code for capturing all of the unique items in a
range. The code needs to be referenced to "Microsoft Scripting Runtime"

Sub test()
Dim dicItem As Variant 'Items within dictionary object
Dim dic As Scripting.Dictionary 'Dictionary Object

Set dic = GetUniqueItems(Sheet1.Range("A1:A10"))
For Each dicItem In dic
MsgBox dicItem
Next dicItem

End Sub


Private Function GetUniqueItems(ByVal rng As Range) As Scripting.Dictionary
Dim cell As Range 'Current cell in range to check
Dim dic As Scripting.Dictionary 'Dictionary Object
Dim dicItem As Variant 'Items within dictionary object

'Confirm there is a relevant range selected
If Not rng Is Nothing Then
'Create dictionay object
Set dic = New Scripting.Dictionary

'Populate dictionary object with unique items (use key to define
unique)
For Each cell In rng 'Traverse selected range
If Not dic.Exists(cell.Value) And cell.Value < Empty Then
'Check the key
dic.Add cell.Value, cell.Value 'Add the item if unique
End If
Next
End If
Set GetUniqueItems = dic
End Function

--
HTH...

Jim Thomlinson


"filo666" wrote:

I belive it's very simple what i'm tryng to accomplish, but I dont have the
functions:

Columns/Rows a b c d e f
1 si
2 so
3 si
4 si
5
6 su
7 sr
8 d
9
10 as
in a array ( and so on in my combobox) should appear ap1(si,so,su,sr,d,as)
tnks in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default An easy one: Help with some VB funct about list and filter

as always, thanks jim¡¡¡¡¡¡¡¡¡¡

"Jim Thomlinson" wrote:

Here is some fairly generic code for capturing all of the unique items in a
range. The code needs to be referenced to "Microsoft Scripting Runtime"

Sub test()
Dim dicItem As Variant 'Items within dictionary object
Dim dic As Scripting.Dictionary 'Dictionary Object

Set dic = GetUniqueItems(Sheet1.Range("A1:A10"))
For Each dicItem In dic
MsgBox dicItem
Next dicItem

End Sub


Private Function GetUniqueItems(ByVal rng As Range) As Scripting.Dictionary
Dim cell As Range 'Current cell in range to check
Dim dic As Scripting.Dictionary 'Dictionary Object
Dim dicItem As Variant 'Items within dictionary object

'Confirm there is a relevant range selected
If Not rng Is Nothing Then
'Create dictionay object
Set dic = New Scripting.Dictionary

'Populate dictionary object with unique items (use key to define
unique)
For Each cell In rng 'Traverse selected range
If Not dic.Exists(cell.Value) And cell.Value < Empty Then
'Check the key
dic.Add cell.Value, cell.Value 'Add the item if unique
End If
Next
End If
Set GetUniqueItems = dic
End Function

--
HTH...

Jim Thomlinson


"filo666" wrote:

I belive it's very simple what i'm tryng to accomplish, but I dont have the
functions:

Columns/Rows a b c d e f
1 si
2 so
3 si
4 si
5
6 su
7 sr
8 d
9
10 as
in a array ( and so on in my combobox) should appear ap1(si,so,su,sr,d,as)
tnks in advance

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default An easy one: Help with some VB funct about list and filter

Ok tim, starting with:

Sub dsgf()
Dim cell As Range
ActiveSheet.Range("A1", Range("A65535").End(xlUp)).Cells.Select
aa = Selection.Value
For Each cell In aa
If Not aa.Exists(cell.Value) And cell.Value < Empty Then
aa.Add cell.Value, cell.Value 'Add the item if unique
End If
Next
End Sub

why is not working??

"Jim Thomlinson" wrote:

Here is some fairly generic code for capturing all of the unique items in a
range. The code needs to be referenced to "Microsoft Scripting Runtime"

Sub test()
Dim dicItem As Variant 'Items within dictionary object
Dim dic As Scripting.Dictionary 'Dictionary Object

Set dic = GetUniqueItems(Sheet1.Range("A1:A10"))
For Each dicItem In dic
MsgBox dicItem
Next dicItem

End Sub


Private Function GetUniqueItems(ByVal rng As Range) As Scripting.Dictionary
Dim cell As Range 'Current cell in range to check
Dim dic As Scripting.Dictionary 'Dictionary Object
Dim dicItem As Variant 'Items within dictionary object

'Confirm there is a relevant range selected
If Not rng Is Nothing Then
'Create dictionay object
Set dic = New Scripting.Dictionary

'Populate dictionary object with unique items (use key to define
unique)
For Each cell In rng 'Traverse selected range
If Not dic.Exists(cell.Value) And cell.Value < Empty Then
'Check the key
dic.Add cell.Value, cell.Value 'Add the item if unique
End If
Next
End If
Set GetUniqueItems = dic
End Function

--
HTH...

Jim Thomlinson


"filo666" wrote:

I belive it's very simple what i'm tryng to accomplish, but I dont have the
functions:

Columns/Rows a b c d e f
1 si
2 so
3 si
4 si
5
6 su
7 sr
8 d
9
10 as
in a array ( and so on in my combobox) should appear ap1(si,so,su,sr,d,as)
tnks in advance

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default An easy one: Help with some VB funct about list and filter

Sub dsgf()
Dim cell As Range
Dim aa as range
Dim dic as scripting.dictionary
set aa = ActiveSheet.Range("A1", Range("A65535").End(xlUp))
For Each cell In aa
If Not dic.Exists(cell.Value) And cell.Value < Empty Then
dic.Add cell.Value, cell.Value 'Add the item if unique
End If
Next cell
End Sub

That should be close. Or if you want...

Sub test()
Dim dicItem As Variant 'Items within dictionary object
Dim dic As Scripting.Dictionary 'Dictionary Object
Dim aa as range

set aa = ActiveSheet.Range("A1", Range("A65535").End(xlUp))

Set dic = GetUniqueItems(aa)
For Each dicItem In dic
MsgBox dicItem
Next dicItem

End Sub


Private Function GetUniqueItems(ByVal rng As Range) As Scripting.Dictionary
Dim cell As Range 'Current cell in range to check
Dim dic As Scripting.Dictionary 'Dictionary Object
Dim dicItem As Variant 'Items within dictionary object

'Confirm there is a relevant range selected
If Not rng Is Nothing Then
'Create dictionay object
Set dic = New Scripting.Dictionary

'Populate dictionary object with unique items (use key to define
unique)
For Each cell In rng 'Traverse selected range
If Not dic.Exists(cell.Value) And cell.Value < Empty Then
'Check the key
dic.Add cell.Value, cell.Value 'Add the item if unique
End If
Next
End If
Set GetUniqueItems = dic
End Function

--
HTH...

Jim Thomlinson


"filo666" wrote:

Ok tim, starting with:

Sub dsgf()
Dim cell As Range
ActiveSheet.Range("A1", Range("A65535").End(xlUp)).Cells.Select
aa = Selection.Value
For Each cell In aa
If Not aa.Exists(cell.Value) And cell.Value < Empty Then
aa.Add cell.Value, cell.Value 'Add the item if unique
End If
Next
End Sub

why is not working??

"Jim Thomlinson" wrote:

Here is some fairly generic code for capturing all of the unique items in a
range. The code needs to be referenced to "Microsoft Scripting Runtime"

Sub test()
Dim dicItem As Variant 'Items within dictionary object
Dim dic As Scripting.Dictionary 'Dictionary Object

Set dic = GetUniqueItems(Sheet1.Range("A1:A10"))
For Each dicItem In dic
MsgBox dicItem
Next dicItem

End Sub


Private Function GetUniqueItems(ByVal rng As Range) As Scripting.Dictionary
Dim cell As Range 'Current cell in range to check
Dim dic As Scripting.Dictionary 'Dictionary Object
Dim dicItem As Variant 'Items within dictionary object

'Confirm there is a relevant range selected
If Not rng Is Nothing Then
'Create dictionay object
Set dic = New Scripting.Dictionary

'Populate dictionary object with unique items (use key to define
unique)
For Each cell In rng 'Traverse selected range
If Not dic.Exists(cell.Value) And cell.Value < Empty Then
'Check the key
dic.Add cell.Value, cell.Value 'Add the item if unique
End If
Next
End If
Set GetUniqueItems = dic
End Function

--
HTH...

Jim Thomlinson


"filo666" wrote:

I belive it's very simple what i'm tryng to accomplish, but I dont have the
functions:

Columns/Rows a b c d e f
1 si
2 so
3 si
4 si
5
6 su
7 sr
8 d
9
10 as
in a array ( and so on in my combobox) should appear ap1(si,so,su,sr,d,as)
tnks in advance



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default An easy one: Help with some VB funct about list and filter

but an errors appears: the user defined type hasn't been defined
(something about the Dim dic as scripting.dictionary)

"Jim Thomlinson" wrote:

Sub dsgf()
Dim cell As Range
Dim aa as range
Dim dic as scripting.dictionary
set aa = ActiveSheet.Range("A1", Range("A65535").End(xlUp))
For Each cell In aa
If Not dic.Exists(cell.Value) And cell.Value < Empty Then
dic.Add cell.Value, cell.Value 'Add the item if unique
End If
Next cell
End Sub

That should be close. Or if you want...

Sub test()
Dim dicItem As Variant 'Items within dictionary object
Dim dic As Scripting.Dictionary 'Dictionary Object
Dim aa as range

set aa = ActiveSheet.Range("A1", Range("A65535").End(xlUp))

Set dic = GetUniqueItems(aa)
For Each dicItem In dic
MsgBox dicItem
Next dicItem

End Sub


Private Function GetUniqueItems(ByVal rng As Range) As Scripting.Dictionary
Dim cell As Range 'Current cell in range to check
Dim dic As Scripting.Dictionary 'Dictionary Object
Dim dicItem As Variant 'Items within dictionary object

'Confirm there is a relevant range selected
If Not rng Is Nothing Then
'Create dictionay object
Set dic = New Scripting.Dictionary

'Populate dictionary object with unique items (use key to define
unique)
For Each cell In rng 'Traverse selected range
If Not dic.Exists(cell.Value) And cell.Value < Empty Then
'Check the key
dic.Add cell.Value, cell.Value 'Add the item if unique
End If
Next
End If
Set GetUniqueItems = dic
End Function

--
HTH...

Jim Thomlinson


"filo666" wrote:

Ok tim, starting with:

Sub dsgf()
Dim cell As Range
ActiveSheet.Range("A1", Range("A65535").End(xlUp)).Cells.Select
aa = Selection.Value
For Each cell In aa
If Not aa.Exists(cell.Value) And cell.Value < Empty Then
aa.Add cell.Value, cell.Value 'Add the item if unique
End If
Next
End Sub

why is not working??

"Jim Thomlinson" wrote:

Here is some fairly generic code for capturing all of the unique items in a
range. The code needs to be referenced to "Microsoft Scripting Runtime"

Sub test()
Dim dicItem As Variant 'Items within dictionary object
Dim dic As Scripting.Dictionary 'Dictionary Object

Set dic = GetUniqueItems(Sheet1.Range("A1:A10"))
For Each dicItem In dic
MsgBox dicItem
Next dicItem

End Sub


Private Function GetUniqueItems(ByVal rng As Range) As Scripting.Dictionary
Dim cell As Range 'Current cell in range to check
Dim dic As Scripting.Dictionary 'Dictionary Object
Dim dicItem As Variant 'Items within dictionary object

'Confirm there is a relevant range selected
If Not rng Is Nothing Then
'Create dictionay object
Set dic = New Scripting.Dictionary

'Populate dictionary object with unique items (use key to define
unique)
For Each cell In rng 'Traverse selected range
If Not dic.Exists(cell.Value) And cell.Value < Empty Then
'Check the key
dic.Add cell.Value, cell.Value 'Add the item if unique
End If
Next
End If
Set GetUniqueItems = dic
End Function

--
HTH...

Jim Thomlinson


"filo666" wrote:

I belive it's very simple what i'm tryng to accomplish, but I dont have the
functions:

Columns/Rows a b c d e f
1 si
2 so
3 si
4 si
5
6 su
7 sr
8 d
9
10 as
in a array ( and so on in my combobox) should appear ap1(si,so,su,sr,d,as)
tnks in advance

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default An easy one: Help with some VB funct about list and filter

The code needs to be referenced to "Microsoft Scripting Runtime". In the VBE
Select Tools- References and check "Microsoft Scripting Runtime".

--
HTH...

Jim Thomlinson


"filo666" wrote:

but an errors appears: the user defined type hasn't been defined
(something about the Dim dic as scripting.dictionary)

"Jim Thomlinson" wrote:

Sub dsgf()
Dim cell As Range
Dim aa as range
Dim dic as scripting.dictionary
set aa = ActiveSheet.Range("A1", Range("A65535").End(xlUp))
For Each cell In aa
If Not dic.Exists(cell.Value) And cell.Value < Empty Then
dic.Add cell.Value, cell.Value 'Add the item if unique
End If
Next cell
End Sub

That should be close. Or if you want...

Sub test()
Dim dicItem As Variant 'Items within dictionary object
Dim dic As Scripting.Dictionary 'Dictionary Object
Dim aa as range

set aa = ActiveSheet.Range("A1", Range("A65535").End(xlUp))

Set dic = GetUniqueItems(aa)
For Each dicItem In dic
MsgBox dicItem
Next dicItem

End Sub


Private Function GetUniqueItems(ByVal rng As Range) As Scripting.Dictionary
Dim cell As Range 'Current cell in range to check
Dim dic As Scripting.Dictionary 'Dictionary Object
Dim dicItem As Variant 'Items within dictionary object

'Confirm there is a relevant range selected
If Not rng Is Nothing Then
'Create dictionay object
Set dic = New Scripting.Dictionary

'Populate dictionary object with unique items (use key to define
unique)
For Each cell In rng 'Traverse selected range
If Not dic.Exists(cell.Value) And cell.Value < Empty Then
'Check the key
dic.Add cell.Value, cell.Value 'Add the item if unique
End If
Next
End If
Set GetUniqueItems = dic
End Function

--
HTH...

Jim Thomlinson


"filo666" wrote:

Ok tim, starting with:

Sub dsgf()
Dim cell As Range
ActiveSheet.Range("A1", Range("A65535").End(xlUp)).Cells.Select
aa = Selection.Value
For Each cell In aa
If Not aa.Exists(cell.Value) And cell.Value < Empty Then
aa.Add cell.Value, cell.Value 'Add the item if unique
End If
Next
End Sub

why is not working??

"Jim Thomlinson" wrote:

Here is some fairly generic code for capturing all of the unique items in a
range. The code needs to be referenced to "Microsoft Scripting Runtime"

Sub test()
Dim dicItem As Variant 'Items within dictionary object
Dim dic As Scripting.Dictionary 'Dictionary Object

Set dic = GetUniqueItems(Sheet1.Range("A1:A10"))
For Each dicItem In dic
MsgBox dicItem
Next dicItem

End Sub


Private Function GetUniqueItems(ByVal rng As Range) As Scripting.Dictionary
Dim cell As Range 'Current cell in range to check
Dim dic As Scripting.Dictionary 'Dictionary Object
Dim dicItem As Variant 'Items within dictionary object

'Confirm there is a relevant range selected
If Not rng Is Nothing Then
'Create dictionay object
Set dic = New Scripting.Dictionary

'Populate dictionary object with unique items (use key to define
unique)
For Each cell In rng 'Traverse selected range
If Not dic.Exists(cell.Value) And cell.Value < Empty Then
'Check the key
dic.Add cell.Value, cell.Value 'Add the item if unique
End If
Next
End If
Set GetUniqueItems = dic
End Function

--
HTH...

Jim Thomlinson


"filo666" wrote:

I belive it's very simple what i'm tryng to accomplish, but I dont have the
functions:

Columns/Rows a b c d e f
1 si
2 so
3 si
4 si
5
6 su
7 sr
8 d
9
10 as
in a array ( and so on in my combobox) should appear ap1(si,so,su,sr,d,as)
tnks in advance

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
filter: how to print filter list options in dropdown box help please Excel Discussion (Misc queries) 2 October 17th 07 01:53 AM
how do i enable a drop down list depending on result of "if" funct Varun Excel Worksheet Functions 3 August 8th 06 04:44 PM
Easy Filter CBrausa Excel Discussion (Misc queries) 3 March 7th 06 07:15 PM
Is there an easy way to filter duplicate rows of data in excel? Yumin Excel Discussion (Misc queries) 1 October 7th 05 08:15 PM
Very easy question about filter!!! Wilmarjr Excel Discussion (Misc queries) 2 June 27th 05 06:29 PM


All times are GMT +1. The time now is 09:51 AM.

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

About Us

"It's about Microsoft Excel"