vba compare arrays and remove exact matching arrays

jacojvv

New Member
Joined
Aug 13, 2012
Messages
5
Hi
I need help to create a <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">vba</acronym> that will compare all arrays to each other ,example listed below they are sepperated by 1 blank line and to remove any of them that have all 30 identical nrs in identical positions.(in this example the firs and last array are identical)

301632361523
13174593441
273133392537
433619285
122210262418
37925132819
224317163141
333634321218
45102615627
3932353024
173931193734
91536121016
43252633322
45283013524
18623413227
12433433185
6261592830
174122453616
253710271319
32324313932
301632361523
13174593441
273133392537
433619285
122210262418

<tbody>
</tbody>


<tbody>
</tbody>
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hello,

Here's the skeleton of the code, you only stil need to compare the strings, the result of the concatenations.

Code:
Sub wigi()

    For Each ar In Columns(1).SpecialCells(2, 1).Areas
        
        For Each ar_2 In Columns(1).SpecialCells(2, 1).Areas
        
            If ar_2.Row > ar.Row Then
            
                Debug.Print ConCat("-", ar.Cells(1).CurrentRegion), ConCat("-", ar_2.Cells(1).CurrentRegion)
            
            End If
        
        Next
        
    Next


End Sub


Function ConCat(Delimiter As Variant, ParamArray CellRanges() As Variant) As String


    Dim Cell As Range, Area As Variant


    If IsMissing(Delimiter) Then Delimiter = ""


    For Each Area In CellRanges
        If TypeName(Area) = "Range" Then
            For Each Cell In Area
                If Len(Cell.Value) Then ConCat = ConCat & Delimiter & Cell.Value
            Next
        Else
            ConCat = ConCat & Delimiter & Area
        End If
    Next


    ConCat = Mid(ConCat, Len(Delimiter) + 1)
End Function
 
Upvote 0
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG18Oct55
[COLOR="Navy"]Dim[/COLOR] Rng         [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Dn          [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] A           [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Str         [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = UsedRange.SpecialCells(xlCellTypeConstants)
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng.Areas
    Str = vbNullString
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] A [COLOR="Navy"]In[/COLOR] Dn
            Str = Str & A
        [COLOR="Navy"]Next[/COLOR] A
            [COLOR="Navy"]If[/COLOR] Not .Exists(Str) [COLOR="Navy"]Then[/COLOR]
                .Add Str, Nothing
            [COLOR="Navy"]Else[/COLOR]
               Dn.ClearContents
            [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Hi

I changed Mick's contribution in 4 ways:

- Str should not be used in such a way
- UsedRange needs to be qualified
- without a delimiter in the string variable, strange results could be obtained
- I shortened the code


Code:
Sub MG18Oct55_Wigi()
    With CreateObject("scripting.dictionary")
        .CompareMode = vbTextCompare
        For Each Dn In ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants).Areas
            myStr = ""
            For Each A In Dn
                myStr = myStr & "-" & A
            Next
            
            If Not .Exists(myStr) Then
                .Add myStr, Nothing
            Else
                Dn.ClearContents
            End If
        Next
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,350
Messages
6,124,430
Members
449,158
Latest member
burk0007

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top