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

[TABLE="class: grid, width: 50, align: center"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]Z[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]Z[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]Z[/TD]
[TD]A[/TD]
[/TR]
</tbody>[/TABLE]

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

[TABLE="class: grid, width: 50, align: left"]
<tbody>[TR]
[TD]B[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]Z[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]Z[/TD]
[/TR]
[TR]
[TD]Z[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]Z[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
</tbody>[/TABLE]



Many thanks for reading and any suggestion welcome
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,224,833
Messages
6,181,242
Members
453,026
Latest member
cknader

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