Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Remove Duplicate Array Items


Hi all,

I am trying to figure out how to remove duplicate values from an arra
in VBA. Can anyone point me in the right direction?

Thanks!
Eri

--
erikc
-----------------------------------------------------------------------
erikcw's Profile: http://www.excelforum.com/member.php...fo&userid=2879
View this thread: http://www.excelforum.com/showthread.php?threadid=48770

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Remove Duplicate Array Items

One way:

Option Explicit
Sub testme()

Dim myArr As Variant
Dim myColl As Collection
Dim iCtr As Long
myArr = Array("a", "B", 99, "a", "A")

Set myColl = New Collection

On Error Resume Next
For iCtr = LBound(myArr) To UBound(myArr)
myColl.Add myArr(iCtr), CStr(myArr(iCtr))
Next iCtr
On Error Resume Next

ReDim myArr(LBound(myArr) To LBound(myArr) + myColl.Count - 1)

For iCtr = 1 To myColl.Count
myArr(LBound(myArr) + iCtr - 1) = myColl.Item(iCtr)
Next iCtr

'did it work
For iCtr = LBound(myArr) To UBound(myArr)
Debug.Print myArr(iCtr)
Next iCtr

End Sub

John Walkenbach shows a way to sort that collection at:
http://j-walk.com/ss/excel/tips/tip47.htm





erikcw wrote:

Hi all,

I am trying to figure out how to remove duplicate values from an array
in VBA. Can anyone point me in the right direction?

Thanks!
Erik

--
erikcw
------------------------------------------------------------------------
erikcw's Profile: http://www.excelforum.com/member.php...o&userid=28797
View this thread: http://www.excelforum.com/showthread...hreadid=487707


--

Dave Peterson
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
Duplicate items [email protected] Excel Discussion (Misc queries) 4 August 19th 08 08:27 PM
Deleting Duplicate items in a ListBox CLamar Excel Discussion (Misc queries) 24 June 13th 06 06:22 PM
How to get rid off duplicate items? Svea Excel Discussion (Misc queries) 5 October 24th 05 12:34 AM
Duplicate Items Andy Daugherty Excel Programming 1 March 3rd 04 02:17 PM
Duplicate Items Andy Daugherty Excel Programming 1 March 2nd 04 11:22 PM


All times are GMT +1. The time now is 01:40 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"