Lookup-multiple-particial values-in-one-cell

asallame

New Member
Joined
Aug 25, 2020
Messages
18
Office Version
  1. 2010
Platform
  1. Windows
HELLO EVERY BODY

I’d like to complete vba formula with the expected result at attach file , i am sorry for my bad english language .

vba code

'Name the UDF and declare arguments and data types
Function Lookup_concat(Search_string As String, _
Search_in_col As Range, Return_val_col As Range)

'Dimension variables and declare data types
Dim i As Long, Result As String
Dim Search_strings, Value As Variant

'Split string using a delimiting character and return an array of values
Search_strings = Split(Search_string, ";")

'Iterate through values in array
For Each Value In Search_strings

'Iterate through from 1 to the number of cells in Search_in_col
For i = 1 To Search_in_col.Count

'Check if cell value is equal to value in variable Value
If Search_in_col.Cells(i, 1) = Value Then

'Save the corresponding return value to variable result
Result = Result & "," & Return_val_col.Cells(i, 1).Value
End If

'Continue with next number
Next i

'Continue with next value
Next Value

'Return values saved to result to worksheet
Lookup_concat = Trim(Result)

End Function


note
vba code is not mine


thank u


Lookup-multiple-particial values-in-one-cell - Copy.xlsm
ABCDEFGH
1
2ServersApplications
3AD1,AD5,AD3APP1
4AD4APP2
5AD1APP2
6AD2APP4
7AD2APP5
8AD4,AD2APP6
9AD3APP7
10AD3APP8
11AD5APP9
12
13
14
15
16
17
18
19ServersApplicationsEXPECTED RESULTS WITH ALL MATCHING PARTIAL STRING OF LISTFINAL EXPECTED RESULTS WITHOUT DUPLICATED
20AD1;AD3,APP2,APP7,APP8APP1,APP2,APP1,APP7,APP8APP1,APP2,APP7,APP8
21AD4;AD5,APP2,APP9APP2,APP6,APP1,APP9APP2,APP6,APP1,APP9
22
23
24
Sheet1
Cell Formulas
RangeFormula
C20:C21C20=Lookup_concat(B20,Sheet1!$B$3:$B$11,Sheet1!$C$3:$C$11)
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try this variant:
VBA Code:
Function Lookup_concat(Search_string As String, Search_in_col As Range, Return_val_col As Range)
'Dimension variables and declare data types
Dim i As Long, Result As String
Dim Search_strings, Value As Variant
Dim ServerS, IApp()

'Split string using a delimiting character and return an array of values
Search_strings = Split(Search_string, ";")
ReDim IApp(1 To Return_val_col.Rows.Count)          'List of inserted Apps
'Iterate through values in array
For Each Value In Search_strings
'Iterate through from 1 to the number of cells in Search_in_col
    For i = 1 To Search_in_col.Count
        If Search_in_col.Cells(i, 1).Value <> "" Then
            ServerS = Split(Search_in_col.Cells(i, 1).Value, ",", , vbTextCompare)
            If Not IsError(Application.Match(Value, ServerS, False)) Then
                If IsError(Application.Match(Return_val_col.Cells(i, 1).Value, IApp, False)) Then
                    'Save the corresponding return value to variable result
                    Result = Result & "," & Return_val_col.Cells(i, 1).Value
                    IApp(i) = Return_val_col.Cells(i, 1).Value
                End If
            End If
        End If
    Next i
Next Value
'Return values saved to result to worksheet
Lookup_concat = Trim(Mid(Result, 2))
End Function
Bye
 
Upvote 0
Another way

VBA Code:
Function Lookup_concat(Search_string As String, Search_in_col As Range, Return_val_col As Range) As String
  Dim d As Object, RX As Object
  Dim a As Variant, b As Variant
  Dim i As Long
 
  a = Search_in_col.Value
  b = Return_val_col.Value
  Set d = CreateObject("Scripting.Dictionary")
  Set RX = CreateObject("VBScript.RegExp")
  RX.Pattern = "\b(" & Replace(Search_string, ";", "|") & ")\b"
  For i = 1 To UBound(a)
    If RX.Test(a(i, 1)) Then d(b(i, 1)) = 1
  Next i
  If d.Count > 0 Then Lookup_concat = Join(d.Keys(), ",")
End Function

asallame 1.xlsm
ABC
1
2ServersApplications
3AD1,AD5,AD3APP1
4AD4APP2
5AD1APP2
6AD2APP4
7AD2APP5
8AD4,AD2APP6
9AD3APP7
10AD3APP8
11AD5APP9
12
18
19ServersApplications
20AD1;AD3APP1,APP2,APP7,APP8
21AD4;AD5APP1,APP2,APP6,APP9
22
Sheet1
Cell Formulas
RangeFormula
C20:C21C20=Lookup_concat(B20,Sheet1!$B$3:$B$11,Sheet1!$C$3:$C$11)


If your function formulas and the table are in fact all on Sheet1 then of course you do not need the Sheet1 references in the formula. It would just be
=Lookup_concat(B20,$B$3:$B$11,$C$3:$C$11)
 
Upvote 0
You're welcome. Thanks for the follow up. Glad we could help. :)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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