Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Deleting Repeating Values from an Array

Hello,

I have a macro that writes values from cells into an array. Is it possible
to delete repetitive values from the array or create another array that would
only have different values?

Any help on how to accomplish the above would be greatly appreciated.

Thank You!

Magnivy


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 200
Default Deleting Repeating Values from an Array

Magnivy wrote:
Hello,

I have a macro that writes values from cells into an array. Is it possible
to delete repetitive values from the array or create another array that would
only have different values?

Any help on how to accomplish the above would be greatly appreciated.

Thank You!

Magnivy


If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook

arr2=ArrayUniques(arr1) will do it.

Use of the ArrayUniques will require that there be an effective
reference to Microsoft Scripting Runtime.

Alan Beban
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Deleting Repeating Values from an Array

This is very helpful. Thank you very much Alan!

"Alan Beban" wrote:

Magnivy wrote:
Hello,

I have a macro that writes values from cells into an array. Is it possible
to delete repetitive values from the array or create another array that would
only have different values?

Any help on how to accomplish the above would be greatly appreciated.

Thank You!

Magnivy


If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook

arr2=ArrayUniques(arr1) will do it.

Use of the ArrayUniques will require that there be an effective
reference to Microsoft Scripting Runtime.

Alan Beban

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Deleting Repeating Values from an Array

Hey Alan,

I tried the ArrayUniques on a worksheet, and it only returned the first
value of the InputArray. Maybe its because I didnt specify a reference to
Microsoft Scripting Runtime? I'm not sure what that means. It would be great
if you could elaborate on that.

Thanks!

Magnivy
"Alan Beban" wrote:

Magnivy wrote:
Hello,

I have a macro that writes values from cells into an array. Is it possible
to delete repetitive values from the array or create another array that would
only have different values?

Any help on how to accomplish the above would be greatly appreciated.

Thank You!

Magnivy


If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook

arr2=ArrayUniques(arr1) will do it.

Use of the ArrayUniques will require that there be an effective
reference to Microsoft Scripting Runtime.

Alan Beban

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Deleting Repeating Values from an Array

This is a function that removes duplicates from a 1-D array.

Function RemoveDuplicates(arr1 As Variant, _
DoSort As Boolean) As Variant

'removes duplicates from a 1D-array
'----------------------------------
Dim NoDupes As New Collection
Dim i As Long
Dim LB As Byte
Dim arr2()

LB = LBound(arr1)

'The next statement ignores the error caused
'by attempting to add a duplicate key to the collection.
'The duplicate is not added - which is just what we want!
'--------------------------------------------------------
On Error Resume Next
For i = LBound(arr1) To UBound(arr1)
NoDupes.Add arr1(i), CStr(arr1(i))
'Note: the 2nd argument (key) for
'the Add method must be a string
'--------------------------------
Next i
On Error GoTo 0

ReDim arr2(LB To NoDupes.Count - (1 - LB))

'copy the collection to array
'----------------------------
For i = 1 To NoDupes.Count
arr2(i - (1 - LB)) = NoDupes(i)
Next i

RemoveDuplicates = arr2

End Function


It would be easy to adjust the code to deal with 2-D arrays.

RBS


"Magnivy" wrote in message
...
Hello,

I have a macro that writes values from cells into an array. Is it possible
to delete repetitive values from the array or create another array that
would
only have different values?

Any help on how to accomplish the above would be greatly appreciated.

Thank You!

Magnivy



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
Deleting Last values in an array gti_jobert[_19_] Excel Programming 3 February 16th 06 10:49 AM
Deleting blank values from an array chemdude77 Excel Programming 2 January 6th 06 07:31 PM
deleting values in a worksheet without deleting the formulas patti Excel Worksheet Functions 1 October 28th 05 09:49 PM
Deleting blank values from an array Rich J[_2_] Excel Programming 6 June 1st 05 11:28 PM
Deleting series of repeating rows Bob Excel Programming 3 December 24th 03 04:28 PM


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