Vlookup every single character of a cell's text

Jubinell

Board Regular
Joined
Jan 17, 2008
Messages
166
Hi,

I have a series of cells that contain some texts of varying lengths.

I'd like to vlookup each and every single character of a particular text. If the result is found, great. If the result is null, I want to return a particular character. If the looked up character cannot be found, I want to return another character. In the end, I want to combine all of these results into a single text string.

So for example, if my lookup table is like this:
A apple
B bean
C computer
D

And say the null qualifier is *null* and the not found qualifier is *NA*, here are some expected results of my formula F():

F("ABC") = "applebeancomputer"
F("BD") = "bean*null*"
F("CDE") = "computer*null**NA*"
F("") = ""

Any ideas to do this with a nested formula?
If not, UDFs would also be fine (although less desirable).
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi

I'm not sure that WS Functions would help since CONCATENATE cannot be used with Array Functions (and I think you would need Array WS Functions).. I may be wrong though....

However, try UDF


Code:
Function f(vInput As Variant, Optional LookupRange As Range) As String
    Dim WFN As WorksheetFunction
    Dim i As Long
    Set WFN = Application.WorksheetFunction
    f = ""
    For i = 1 To Len(vInput)
        If WFN.CountIf(LookupRange.Columns(1), Mid(vInput, i, 1)) > 0 Then
            If Not IsEmpty(WFN.VLookup(Mid(vInput, i, 1), LookupRange, 2, 0)) Then
                f = f & WFN.VLookup(Mid(vInput, i, 1), LookupRange, 2, 0)
            Else
                f = f & "*null*"
            End If
        Else
            f = f & "*N/A*"
        End If
    Next i
End Function
Excel Workbook
ABCDE
19Aappleapplebeancomputer
20Bbeanbean*null*
21Ccomputerbean*N/A*
22D
Core Patch
Excel 2003
Cell Formulas
RangeFormula
E19=F("ABC",$A$19:$B$22)
E20=F("BD",$A$19:$B$22)
E21=F("BE",$A$19:$B$22)
E22=F("",$A$19:$B$22)
<input id="gwProxy" type="hidden"><!--Session data--><input *******="jsCall();" id="jsProxy" type="hidden"><input id="gwProxy" type="hidden"><!--Session data--><input *******="jsCall();" id="jsProxy" type="hidden">
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,539
Members
449,316
Latest member
sravya

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