VBA Different?

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,177
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a list in Column A of grades separated by a Pipe Character. I need a function in column B that tells me if they are different. Thanks in advance!

F|F
A+|A+
A+|A+
A|A
F|F
A+|A+
A-|B+
F|F
A-|F|A-
F|F
F|F
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Give this formula a try...

=IF(LEFT(A1,FIND("|",A1)-1)=MID(A1,FIND("|",A1)+1,9),"","<<==")
 
Upvote 0
Another possibility:

=IF(LEFT(A1,FIND("|",A1)-1)=RIGHT(A1,LEN(A1)-FIND("|",A1)),"Same","Different")

Edit: oops, didn't see that you have some with 3 grades. My bad...
 
Last edited:
Upvote 0
How about
Code:
Function GradeDif(Rng As Range) As Boolean
   Dim i As Long
   GradeDif = True
   For i = 0 To UBound(Split(Rng, "|")) - 1
      If Split(Rng, "|")(i) <> Split(Rng, "|")(i + 1) Then
         GradeDif = False
         Exit For
      End If
   Next i
End Function
& in B1 enter =gradedif(A1) & fill down
 
Upvote 0
Give this formula a try...

=IF(LEFT(A1,FIND("|",A1)-1)=MID(A1,FIND("|",A1)+1,9),"","<<==")
I missed that some of your values could have 2 (or more) pipe characters. Given that, ignore the above formula and use this one instead...

=IF(LEN(SUBSTITUTE(SUBSTITUTE(A1,LEFT(A1,FIND("|",A1)-1),""),"|","")),"<<==","")
 
Upvote 0
Yes it would Rick! Thank you everyone who answered this post. Fluff worked perfectly!
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
I missed that some of your values could have 2 (or more) pipe characters. Given that, ignore the above formula and use this one instead...

=IF(LEN(SUBSTITUTE(SUBSTITUTE(A1,LEFT(A1,FIND("|",A1)-1),""),"|","")),"<<==","")
I missed that you wanted a VBA solution. We can use the above (modified slightly) in a one-liner UDF (user defined function) as follows...
Code:
[table="width: 500"]
[tr]
	[td]Function GradeDif(Rng As Range) As Boolean
  GradeDif = Evaluate(Replace("LEN(SUBSTITUTE(SUBSTITUTE(@,LEFT(@,FIND(""|"",@)-1),""""),""|"",""""))=0", "@", Rng.Address))
End Function[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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