Partial Text match using VBA

TeckTeck

New Member
Joined
Sep 28, 2023
Messages
15
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi i need help with this as i am new to VBA and dont have the knowledge if this can be done.

Column A is the master list, i would need to match Column E to Column A.
As long as all of Column E is found in Column A, then return the corresponding value in Column F to Column C with respect to the row that the text was match with.

Please help if possible or if not possible please let me know too
Screenshot 2023-10-12 at 2.24.13 PM.png
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Book1
ABCDEF
1
2The Fox jump Over3To-88-to1
3Dancing is so cool4How to do2
4I am not sure how to do this2Fox Jump3
5Please Help me 99 is so4
611-To-88-To-321
Sheet1
Cell Formulas
RangeFormula
B2:B6B2=IFERROR(IFERROR(LOOKUP(2,1/(ISNUMBER(SEARCH(" "&$E$2:$E$5&" "," "&A2&" "))),$F$2:$F$5),LOOKUP(2,1/(ISNUMBER(SEARCH($E$2:$E$5,A2))),$F$2:$F$5)),"")
 
Upvote 0
Solution
And, here is VBA solution

VBA Code:
Option Explicit
Sub test()
Dim lr&, i&, j&, rng, res, st1 As String, st2 As String
lr = Cells(Rows.Count, "A").End(xlUp).Row
res = Range("A2:B" & lr).Value
lr = Cells(Rows.Count, "E").End(xlUp).Row
rng = Range("E2:F" & lr).Value
For i = 1 To UBound(res)
    st1 = " " & UCase(res(i, 1)) & " "
    For j = 1 To UBound(rng)
        st2 = " " & UCase(rng(j, 1)) & " "
        If InStr(1, st1, st2) Or InStr(1, st1, "-" & UCase(rng(j, 1)) & "-") Then
            res(i, 2) = rng(j, 2)
            Exit For
        End If
    Next
Next
Range("A2:B10000").ClearContents
Range("A2").Resize(UBound(res), 2).Value = res
End Sub
 
Upvote 0
Book1
ABCDEF
1
2The Fox jump Over3To-88-to1
3Dancing is so cool4How to do2
4I am not sure how to do this2Fox Jump3
5Please Help me 99 is so4
611-To-88-To-321
Sheet1
Cell Formulas
RangeFormula
B2:B6B2=IFERROR(IFERROR(LOOKUP(2,1/(ISNUMBER(SEARCH(" "&$E$2:$E$5&" "," "&A2&" "))),$F$2:$F$5),LOOKUP(2,1/(ISNUMBER(SEARCH($E$2:$E$5,A2))),$F$2:$F$5)),"")
Hi does this work if the master list and reference list are of 2 different worksheet?
 
Upvote 0
You could also try this shorter version.
It assumes that at most only one of the values from Sheet2 column A would be found in the Sheet1 column A value.

TeckTeck.xlsm
AB
1
2To-88-to1
3How to do2
4Fox Jump3
5is so4
Sheet2


TeckTeck.xlsm
AB
1
2The Fox jump Over3
3Dancing is so cool4
4I am not sure how to do this2
5Please Help me 99 
611-To-88-To-321
Sheet1
Cell Formulas
RangeFormula
B2:B6B2=FILTER(Sheet2!B$2:B$5,ISNUMBER(SEARCH(Sheet2!A$2:A$5,A2)),"")
 
Upvote 0
Cheers. Thanks for the confirmation. :)

Also, if you are interested, you can achieve all the results with a single formula in the top cell only without the need to copy it down the rows.

TeckTeck.xlsm
AB
1
2The Fox jump Over3
3Dancing is so cool4
4I am not sure how to do this2
5Please Help me 99
611-To-88-To-321
Sheet1
Cell Formulas
RangeFormula
B2:B6B2=BYROW(A2:A6,LAMBDA(rw,FILTER(Sheet2!B$2:B$5,ISNUMBER(SEARCH(Sheet2!A$2:A$5,rw)),"")))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,215,450
Messages
6,124,912
Members
449,195
Latest member
Stevenciu

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