Writing matched results of column "A" and "B" in "C" column
Hi there,
Hope you're doing well.
My question is about to writing matched results of column "A" and "B" in "C" column. But in each rows separately.
For example:
A B C
ALFAROMEO user,default,alfa.romeo alfa.romeo
So I've names in A column but only one name in one cell. But in the column B have more than one name in each cell which comma-separated.
And some names in A is not the same exactly.
Some contains "1" or does not contain full name. Or in B column last names comes first. For example: beta.alfa instead of alfa.beta
Here is what I mean;
Re: Writing matched results of column "A" and "B" in "C" column
UDF (User-define-formula) in C1 then drag down
=matchText(RangeOfTwoCells)
=matchText(A1:B1)
How?
Alt-F11 to open VBA window, Insert / module, paste below code into:
PHP Code:
Option Explicit Function matchText(ByVal rng As Range) Dim Text1 As String, Text2 As String, sa, sb, s Text1 = LCase(rng.Cells(1, 1).Value) Text2 = LCase(rng.Cells(1, 2).Value) For Each sa In Split(Text2, ",") If sa = Text1 Then matchText = sa Exit Function ElseIf InStr(1, sa, ".") Then sb = Split(sa, ".") s = sb(0) & sb(1) If InStr(1, Text1, s) Or InStr(1, s, Text1) Then matchText = sa Exit Function End If s = sb(1) & sb(0) If InStr(1, Text1, s) Or InStr(1, s, Text1) Then matchText = sa Exit Function End If End If Next matchText = "" End Function
Re: Writing matched results of column "A" and "B" in "C" column
Originally Posted by bebo021999
UDF (User-define-formula) in C1 then drag down
=matchText(RangeOfTwoCells)
=matchText(A1:B1)
How?
Alt-F11 to open VBA window, Insert / module, paste below code into:
PHP Code:
Option Explicit Function matchText(ByVal rng As Range) Dim Text1 As String, Text2 As String, sa, sb, s Text1 = LCase(rng.Cells(1, 1).Value) Text2 = LCase(rng.Cells(1, 2).Value) For Each sa In Split(Text2, ",") If sa = Text1 Then matchText = sa Exit Function ElseIf InStr(1, sa, ".") Then sb = Split(sa, ".") s = sb(0) & sb(1) If InStr(1, Text1, s) Or InStr(1, s, Text1) Then matchText = sa Exit Function End If s = sb(1) & sb(0) If InStr(1, Text1, s) Or InStr(1, s, Text1) Then matchText = sa Exit Function End If End If Next matchText = "" End Function
Save as file as .xlsm
Great! Thank you so much, it works like a charm!
I appreciate you taking the time.
Bookmarks