Comparing Alphanumeric Strings

Meesam

Board Regular
Joined
Nov 23, 2011
Messages
66
Hello Everybody,

I got a simple sheet in which I got some columns of data representing certain grid-line i.e. A-25, B-35, C-41 etc and I got another column in which the data is like B-25.5, C-26.5 etc. I want to compare the both columns and know for each item that which item is bigger or smaller (grid-line sense) than the other. e.g. C-26.5 will surely be lesser than C-41. I need a simple algorithm or code to achieve the same. Would really appreciate quick response.

Regards.
 
So I think everybody just gave up. Anyways still thanks to everyone who contributed. I will surely try to extend the logic given by Mr. Rick to complete my remaining 20%. Regards
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
So guys as promised I'm back with my final solution.
First of all many THANKS to Mr. Rick for giving me overall guideline to sort this one out and also thanks to d4d6 for his "patience" :)

The function is given below and can be used in following way.
Cell A1 = Coordinates (as per the format in drawing) of AREA / LINE / POINT
Cell B1 = Coordinates (as per the format in drawing) of MAIN AREA
Cell C1 = IsInside(A1,B1)

Result will be "TRUE" if A1 falls within boundaries of B1.

Function is as below.

Code:
 Function IsInside(Area As String, Rectangle As String) As Boolean
   
   Dim Parts() As String
   Dim Line1 As String, Line2 As String, Lx1 As Single, Ly1 As Single, Lx2 As String, Ly2 As String
   Dim Rect1 As String, Rect2 As String, Rx1 As Single, Ry1 As Single, Rx2 As String, Ry2 As String
   
   On Error Resume Next
   
   Parts = Split(Replace(Area, " ", ""), "/")
   Line1 = Parts(0)
   Line2 = Parts(1)
   
   If InStr(1, Line1, "-", vbTextCompare) > 0 Then
     Parts = Split(Line1, "-")
     Lx1 = Parts(0)
     Ly1 = Parts(1)
   Else
   Lx1 = Line1
   Ly1 = "0"
   End If
   
   If InStr(1, Line2, "-", vbTextCompare) > 0 Then
     Parts = Split(Line2, "-")
     Lx2 = Parts(0)
     Ly2 = Parts(1)
   Else
   Lx2 = Line2
   Ly2 = 0
   End If
 
   Parts = Split(Replace(Rectangle, " ", ""), "/")
   Rect1 = Parts(0)
   Rect2 = Parts(1)
 
   If InStr(1, Rect1, "-", vbTextCompare) > 0 Then
     Parts = Split(Rect1, "-")
     Rx1 = Parts(0)
     Ry1 = Parts(1)
   Else
     Rx1 = Rect1
     Ry1 = 0
   End If
   
   If InStr(1, Rect2, "-", vbTextCompare) > 0 Then
     Parts = Split(Rect2, "-")
     Rx2 = Parts(0)
     Ry2 = Parts(1)
   Else
     Rx2 = Rect2
     Ry2 = 0
   End If
 
 
 If Lx1 > 0 And Ly1 > 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 > 0 And Rx2 > 0 And Ry2 > 0 Then
     IsInside = Lx1 >= Rx1 And Lx1 <= Ry1 And Lx2 >= Rx2 And Lx2 <= Ry2
 ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 > 0 And Rx2 > 0 And Ry2 > 0 Then
     IsInside = Lx1 >= Rx1 And Lx1 <= Ry1 And Lx2 >= Rx2 And Ly2 <= Ry2
 ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 = 0 And Rx1 > 0 And Ry1 > 0 And Rx2 > 0 And Ry2 > 0 Then
     IsInside = Lx1 >= Rx1 And Lx1 <= Ry1 And Lx2 >= Rx2 And Lx2 <= Ry2
 ElseIf Lx1 > 0 And Ly1 > 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 = 0 And Rx2 > 0 And Ry2 > 0 Then
     IsInside = 0
 ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 = 0 And Rx2 > 0 And Ry2 > 0 Then
     IsInside = Lx1 = Rx1 And Lx2 >= Rx2 And Ly2 <= Ry2
 ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 = 0 And Rx1 > 0 And Ry1 = 0 And Rx2 > 0 And Ry2 > 0 Then
     IsInside = Lx1 = Rx1 And Lx2 >= Rx2 And Lx2 <= Ry2
 ElseIf Lx1 > 0 And Ly1 > 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 = 0 And Rx2 > 0 And Ry2 = 0 Then
     IsInside = 0
 ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 = 0 And Rx2 > 0 And Ry2 = 0 Then
     IsInside = 0
 ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 = 0 And Rx1 > 0 And Ry1 = 0 And Rx2 > 0 And Ry2 = 0 Then
     IsInside = 0
 ElseIf Lx1 > 0 And Ly1 > 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 > 0 And Rx2 > 0 And Ry2 = 0 Then
     IsInside = 0
 ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 > 0 And Rx2 > 0 And Ry2 = 0 Then
     IsInside = 0
 ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 = 0 And Rx1 > 0 And Ry1 > 0 And Rx2 > 0 And Ry2 = 0 Then
     IsInside = 0
 Else
 End If
 
 End Function

Here is the link to graphic explanation of above.
https://www.facebook.com/photo.php?...60449094.73276.288308561232624&type=1&theater
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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