Comparing two cells with delineated values using VBA

bardcaco

New Member
Joined
Oct 9, 2013
Messages
2
I have data in two cells that is comma separated. I want to compare the values in these cells without copying them to new cells if possible.

So if I have list of names, say,
Cell A1: Person X, Person Y
Cell A2: Person Y, Person X

I want the comparison to return that the values are equal (without caring about the order).

Is there a way to do this?

Thanks.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
See if you can use this"
Code:
Sub equate()
Dim Nm1 As Variant, Nm2 As Variant
Nm1 = Split(Range("A1").Value, ",")
Nm2 = Split(Range("A2").Value, ",")
    If UBound(Nm1) <> UBound(Nm2) Then
    MsgBox "Not Equivalent6"
    Exit Sub
    End If
    For i = LBoundINm1 To UBound(Nm1)
        If InStr(Range("A2").Value, Nm1(i)) = 0 Then
            MsgBox "Not Equivalent"
            Exit Sub
        Else
            MsgBox "Equivalent Cell Value"
    End If
    Next
End Sub
 
Upvote 0
Hold up on this. It contains a typo and I am getting an anomaly after I made the correction.
 
Upvote 0
Hold up on this. It contains a typo and I am getting an anomaly after I made the correction.

OK, figured out the problem.

Code:
Sub equate()
Dim Nm1 As Variant, Nm2 As Variant
Nm1 = Split(Range("A1").Value, ",")
Nm2 = Split(Range("A2").Value, ",")
    If UBound(Nm1) <> UBound(Nm2) Then
    MsgBox "Not Equivalent6"
    Exit Sub
    End If
    For i = LBound(Nm1) To UBound(Nm1)
        If InStr(Trim(Range("A2").Value), Trim(Nm1(i))) < 1 Then
            MsgBox "Not Equivalent"
            Exit Sub
        End If
    Next
MsgBox "Equivalent Cell Value"
End Sub
Should work now.
 
Upvote 0
OK, figured out the problem.

Code:
Sub equate()
Dim Nm1 As Variant, Nm2 As Variant
Nm1 = Split(Range("A1").Value, ",")
Nm2 = Split(Range("A2").Value, ",")
    If UBound(Nm1) <> UBound(Nm2) Then
    MsgBox "Not Equivalent6"
    Exit Sub
    End If
    For i = LBound(Nm1) To UBound(Nm1)
        If InStr(Trim(Range("A2").Value), Trim(Nm1(i))) < 1 Then
            MsgBox "Not Equivalent"
            Exit Sub
        End If
    Next
MsgBox "Equivalent Cell Value"
End Sub
Should work now.

Thanks that works!
 
Upvote 0

Forum statistics

Threads
1,216,165
Messages
6,129,250
Members
449,497
Latest member
The Wamp

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