vba Check Col has same count of Values in another Col with the same count of values regardless of the order

gint3232

New Member
Joined
Jan 12, 2015
Messages
16
Hi Everyone,

Does anyone know how to via "VBA" check one COLs Values against another Cols Values, and check that they match each other as in count of each set of Values! I do not wish to use conditional formatting ,as I have lot more manipulating to do before and after I achieving this.

Take the following two examples: first one the condition is not met and the 2nd is met

Col A has 3x "A", 4x"B" and 2x "Z" Where as Col B has 4x"B", 1 x "Z" and 4 x "A"...False

AB
BB
AZ
BB
AA
ZB
BA
BA
ZA

<tbody>
</tbody>

Col A has 3x "A", 4x"B" and 2x "Z" Where as Col B has 4x"B", 2 x "Z" and 3 x "A"...TRUE

BB
ZA
AZ
ZA
BB
BB
AZ
BA
AB

<tbody>
</tbody>



Many thanks for reading and any suggestion welcome
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
How about
Code:
Sub CompareCol()

   Dim Cl As Range
   Dim Cnt As Long
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then
            If WorksheetFunction.CountIf(Range("A:A"), Cl.Value) = WorksheetFunction.CountIf(Range("B:B"), Cl.Value) Then Cnt = Cnt + 1
            .Add Cl.Value, Nothing
         End If
      Next Cl
      If Cnt = .Count Then
         MsgBox True
      Else
         MsgBox False
      End If
   End With
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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