Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Best way to "filter" an array

I have a 1-dimensional array whose members are single letter values, i.e.

V(1) = "A"
V(2) = "B"
V(3) = "C"
V(4) = "A"
V(5) = "B"
V(6) = "A"
V(7) = "B"
V(8) = "A"
V(9) = "B"
V(10) = "C"

I'd like to create a new array that is a filtered version of the array
above, where all duplicates are removed so that each member of the new array
is unique and not repeated, i.e.

A(1) = "A"
A(2) = "B"
A(3) = "C"

Any ideas on the best method? I can possibly visualize doing this with some
loops, but I'm having trouble getting my head around it. Any ideas welcome.

Thanks!

-gk-


================================================== ======================
"The creative act is not the province of remote oracles or rarefied
geniuses but a transparent process that is open to everyone."
-Greg Kot in Wilco Learning How To Die-


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Best way to "filter" an array

Hello
Option Base 1
Sub PutNondups()
Dim v(10)
Dim v2()
v(1) = "A"
v(2) = "B"
v(3) = "C"
v(4) = "A"
v(5) = "B"
v(6) = "A"
v(7) = "B"
v(8) = "A"
v(9) = "B"
v(10) = "C"

Dim Coll As New Collection

For Each Elt In v
On Error Resume Next
Coll.Add Elt, CStr(Elt)
If Err.Number = 0 Then
ReDim Preserve v2(1 To Coll.Count)
v2(Coll.Count) = Elt
End If
On Error GoTo 0
Next

For i = LBound(v2) To UBound(v2)
MsgBox v2(i)
Next i

End Sub

HTH
Cordially
Pascal

"39N 95W" a écrit dans le message de news:
...
I have a 1-dimensional array whose members are single letter values, i.e.

V(1) = "A"
V(2) = "B"
V(3) = "C"
V(4) = "A"
V(5) = "B"
V(6) = "A"
V(7) = "B"
V(8) = "A"
V(9) = "B"
V(10) = "C"

I'd like to create a new array that is a filtered version of the array
above, where all duplicates are removed so that each member of the new
array is unique and not repeated, i.e.

A(1) = "A"
A(2) = "B"
A(3) = "C"

Any ideas on the best method? I can possibly visualize doing this with
some loops, but I'm having trouble getting my head around it. Any ideas
welcome.

Thanks!

-gk-


================================================== ======================
"The creative act is not the province of remote oracles or rarefied
geniuses but a transparent process that is open to everyone."
-Greg Kot in Wilco Learning How To Die-



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Best way to "filter" an array

Thanks for the quick reply! One question: what kind of object is Elt?
It's not a Keyword, is it? I realize it represents an element in the array
v, so should Elt be dimmed as a String if v contains String values?

-gk-

"papou" <cestpasbon@çanonplus wrote in message
...
Hello
Option Base 1
Sub PutNondups()
Dim v(10)
Dim v2()
v(1) = "A"
v(2) = "B"
v(3) = "C"
v(4) = "A"
v(5) = "B"
v(6) = "A"
v(7) = "B"
v(8) = "A"
v(9) = "B"
v(10) = "C"

Dim Coll As New Collection

For Each Elt In v
On Error Resume Next
Coll.Add Elt, CStr(Elt)
If Err.Number = 0 Then
ReDim Preserve v2(1 To Coll.Count)
v2(Coll.Count) = Elt
End If
On Error GoTo 0
Next

For i = LBound(v2) To UBound(v2)
MsgBox v2(i)
Next i

End Sub

HTH
Cordially
Pascal

"39N 95W" a écrit dans le message de news:
...
I have a 1-dimensional array whose members are single letter values, i.e.

V(1) = "A"
V(2) = "B"
V(3) = "C"
V(4) = "A"
V(5) = "B"
V(6) = "A"
V(7) = "B"
V(8) = "A"
V(9) = "B"
V(10) = "C"

I'd like to create a new array that is a filtered version of the array
above, where all duplicates are removed so that each member of the new
array is unique and not repeated, i.e.

A(1) = "A"
A(2) = "B"
A(3) = "C"

Any ideas on the best method? I can possibly visualize doing this with
some loops, but I'm having trouble getting my head around it. Any ideas
welcome.

Thanks!

-gk-


================================================== ======================
"The creative act is not the province of remote oracles or rarefied
geniuses but a transparent process that is open to everyone."
-Greg Kot in Wilco Learning How To Die-





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Best way to "filter" an array

Elt must be declared as Variant to be used in a For Each loop
So you may just add:
Dim Elt
or
Dim Elt As Variant

HTH
Cordially
Pascal

"39N 95W" a écrit dans le message de news:
...
Thanks for the quick reply! One question: what kind of object is Elt?
It's not a Keyword, is it? I realize it represents an element in the
array v, so should Elt be dimmed as a String if v contains String values?

-gk-

"papou" <cestpasbon@çanonplus wrote in message
...
Hello
Option Base 1
Sub PutNondups()
Dim v(10)
Dim v2()
v(1) = "A"
v(2) = "B"
v(3) = "C"
v(4) = "A"
v(5) = "B"
v(6) = "A"
v(7) = "B"
v(8) = "A"
v(9) = "B"
v(10) = "C"

Dim Coll As New Collection

For Each Elt In v
On Error Resume Next
Coll.Add Elt, CStr(Elt)
If Err.Number = 0 Then
ReDim Preserve v2(1 To Coll.Count)
v2(Coll.Count) = Elt
End If
On Error GoTo 0
Next

For i = LBound(v2) To UBound(v2)
MsgBox v2(i)
Next i

End Sub

HTH
Cordially
Pascal

"39N 95W" a écrit dans le message de news:
...
I have a 1-dimensional array whose members are single letter values, i.e.

V(1) = "A"
V(2) = "B"
V(3) = "C"
V(4) = "A"
V(5) = "B"
V(6) = "A"
V(7) = "B"
V(8) = "A"
V(9) = "B"
V(10) = "C"

I'd like to create a new array that is a filtered version of the array
above, where all duplicates are removed so that each member of the new
array is unique and not repeated, i.e.

A(1) = "A"
A(2) = "B"
A(3) = "C"

Any ideas on the best method? I can possibly visualize doing this with
some loops, but I'm having trouble getting my head around it. Any ideas
welcome.

Thanks!

-gk-


================================================== ======================
"The creative act is not the province of remote oracles or rarefied
geniuses but a transparent process that is open to everyone."
-Greg Kot in Wilco Learning How To Die-







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
Pivot Table Report Filter - "OR" instead of "AND" Multiple Filters tommcbrny Excel Discussion (Misc queries) 1 October 29th 09 03:08 AM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
"Type mismatch" when I try to fill an Array variable with "+" [email protected] Excel Discussion (Misc queries) 1 April 17th 07 01:28 PM
How do I use "offset" function in "array formula"? hongguang Excel Discussion (Misc queries) 3 April 4th 07 12:04 AM
If changed array formula reduce ""\""\""\ - signs to #Missing, will it make ... Maria J-son[_2_] Excel Programming 2 March 5th 06 12:20 PM


All times are GMT +1. The time now is 09:07 PM.

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"