Fuzzy Search Function: IF the word "X" is located in adjacent cell then, put "XXX" here

ChrisOK

Well-known Member
Joined
Mar 26, 2003
Messages
601
Need a fuzzy search function that will look to the cell at right and if a certain word is detected within that description, then place a category name here...

(Accounting/categorizing hundreds of rows of bank statement transactions)

Example: Using Manual Method[\b]
A B[\b]
-----------------------------------------------------------------------------------
1 IF="ICE" found, | POS PURCHASE/EFT TRANS 5814 / ICE VENDING Choctaw OK
put "Inventory" |
here...... |
--------------------------------------------------------------------------------

Ideally, having a look up table where the formula pasted in A will look to the table and use whichever item matches:[\b]
Example: Using a More Automated Method with LookUp Table[\b]

A B[\b]
------------------------------------------------------------------------------------------------
1 IF="ICE" found, | POS PURCHASE/EFT TRANS xxx / ICE VENDING CITY ST
on table Col G, copy |
"data from H here...... |
-----------------------------------------------------------------------------------------------
1 IF="SHELL" found, | POS PURCHASE/EFT TRANS xxx / SHELL OIL xxxxxx CITY ST
|
here...... |
-------------------------------------------------------------------------------------------------
1 IF="HARDWARE" | POS PURCHASE/EFT TRANS xxx / WESTLAKE HARDWARE CITY ST
found,
|
here...... |
-------------------------------------------------------------------------------------------------

Lookup Table: (this is what the Col A function would look to/scan down the list for a fuzzy match)[\b]

Col G Col H
LOOK FOR............PASTE THIS CATEGORY
ICE.....................Inventory Expense
SHELL.................Gas Expense
HARDWARE...........Repairs Expense
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
This function should see you right:

Code:
Function FuzzySearch(StringToTest, rngLookUp As Range, rngReturn As Range)

    Dim i As Integer, Test As Variant

    If rngLookUp.Rows.Count <> rngReturn.Rows.Count Or rngLookUp.Columns.Count <> rngReturn.Columns.Count Then
        FuzzySearch = "ERROR - Lookup and Return ranges are different sizes."
        Exit Function
    End If

    On Error Resume Next

    For i = 1 To rngLookUp.Cells.Count
    
        If IsError(Application.WorksheetFunction.Find(rngLookUp.Cells(i).Value, StringToTest)) Then
    
        Else
            FuzzySearch = rngReturn.Cells(i).Value
            Exit Function
        End If
    Next i

    On Error GoTo 0

    FuzzySearch = ""


End Function
 
Upvote 0
Not sure how to implement this... when I mentioned 'function' I meant a formula/function... to paste down Column A and have it look to Col B.
Something like =LOOKUP..blah..blah..blah

I'm familiar with using Sub () frequently in vba, running them from customizing ribbon buttons or via the Macro editor -- but not so much on functions.. if you can expand on running it - I may be able to use this..
 
Upvote 0
Not sure how to implement this... when I mentioned 'function' I meant a formula/function... to paste down Column A and have it look to Col B.
Something like =LOOKUP..blah..blah..blah

I'm familiar with using Sub () frequently in vba, running them from customizing ribbon buttons or via the Macro editor -- but not so much on functions.. if you can expand on running it - I may be able to use this..

If I may answer for the Glove_Man, this is what he had in mind.

The VBA creates a User Defined Function (UDF). Just paste it in the normal VBA Module, and enter it as shown.


Excel 2010
ABCDEFGH
1POS PURCHASE/EFT TRANS 5814 / ICE VENDING Choctaw OKInventory ExpenseLOOK FORPASTE THIS CATEGORY
2POS PURCHASE/EFT TRANS xxx / ICE VENDING CITY STInventory ExpenseICEInventory Expense
3POS PURCHASE/EFT TRANS xxx / SHELL OIL xxxxxx CITY STGas ExpenseSHELLGas Expense
4POS PURCHASE/EFT TRANS xxx / WESTLAKE HARDWARE CITY STRepairs ExpenseHARDWARERepairs Expense
Sheet1
Cell Formulas
RangeFormula
B1=fuzzysearch(A1,$G$1:$G$4,$H$1:$H$4)
B2=fuzzysearch(A2,$G$1:$G$4,$H$1:$H$4)
B3=fuzzysearch(A3,$G$1:$G$4,$H$1:$H$4)
B4=fuzzysearch(A4,$G$1:$G$4,$H$1:$H$4)
 
Upvote 0
David - with quality like that you may answer for me at any time! :-)

Chris - sorry, I saw the html tags in your original post and assumed... Have you managed to get the function working?

Once you have placed the function into a module in the VBA editor, you can use the function as you would a standard Excel function, including copying it down the column.
 
Last edited:
Upvote 0
OMG - just tested it out and it is AMAAAAAZING! Love it Guys! So kool! You two make a great team!
The example/explanation was fabulous...and of course, the vba function is spot on!

Thanks!
Learned something new and will use it to help relieve some pain for others dealing with thousands of lines of data that need quickly categorized...
Many Thanks! Cheers! :beerchug:
 
Upvote 0
OMG - just tested it out and it is AMAAAAAZING! Love it Guys! So kool! You two make a great team!
The example/explanation was fabulous...and of course, the vba function is spot on!

Thanks!
Learned something new and will use it to help relieve some pain for others dealing with thousands of lines of data that need quickly categorized...
Many Thanks! Cheers! :beerchug:

You're welcome Chris - your pleasure brings me pleasure!
 
Upvote 0
FYI: I clicked "LIKE" on both your posts to help you guys out on your ratings!
Hv a great wk-end!
 
Upvote 0

Forum statistics

Threads
1,226,112
Messages
6,189,041
Members
453,521
Latest member
Chris_Hed

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