partial vlookup and auto update the incomplete word that contains "-"

amrans20

New Member
Joined
Feb 22, 2020
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hello, I've search threads with tags autocomplete and vlookup but haven't found some similarities with what I need, so hopefully someone can help. this is my 2nd post, please go gentle on me if this question has already been asked.

What I would like to find is a way for auto updating a part of the text in a cell with list of the complete version of that text. The text always contains a dash "-".


example (column A)list (column C)
Swap from KGLR-EN1 to KGL-EN1-TRTTSS-KGLR-EN1-TRTT
Migrate from TGLR-en1 and KGL-pn1 to KGL-EN1-TRTTSS-KGL-EN1-TRT
TGLR-en1-TRs2
TSS-KGL-pn1-TR8
TSS-KGL-EN1-TRT

i'm hoping that i could get a formula or VBA code that would get:

Desired Result (column B)
Swap from TSS-KGLR-EN1-TRTT to TSS-KGL-EN1-TRT
Migrate from TGLR-en1-TRs2 and TSS-KGL-pn1-TR8 to TSS-KGL-EN1-TRT

Any help would be much appreciated. Thank you for your time. ?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try this UDF

VBA Code:
Function CompleteWords(sText As String, list As Range)
  Dim t As Variant, cad As String, f As Range, newText As Variant
  For Each t In Split(sText, " ")
    newText = t
    If InStr(1, t, "-") > 0 Then
      Set f = list.Find(t, , xlValues, xlPart)
      If Not f Is Nothing Then newText = f.Value
    End If
    cad = cad & newText & " "
  Next
  CompleteWords = Trim(cad)
End Function

HOW TO INSTALL UDFs
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use CompleteWords just like it was a built-in Excel function. For example:

Dante Amor
ABC
1EXAMPLEDesired ResultLIST
2Swap from KGLR-EN1 to KGL-EN1-TRTSwap from TSS-KGLR-EN1-TRTT to TSS-KGL-EN1-TRTTSS-KGLR-EN1-TRTT
3Migrate from TGLR-en1 and KGL-pn1 to KGL-EN1-TRTMigrate from TGLR-en1-TRs2 and TSS-KGL-pn1-TR8 to TSS-KGL-EN1-TRTTSS-KGL-EN1-TRT
4TGLR-en1-TRs2
5TSS-KGL-pn1-TR8
6TSS-KGL-EN1-TRT
Sh
Cell Formulas
RangeFormula
B2:B3B2=CompleteWords(A2,$C$2:$C$6)
 
Upvote 0
Try this UDF

VBA Code:
Function CompleteWords(sText As String, list As Range)
  Dim t As Variant, cad As String, f As Range, newText As Variant
  For Each t In Split(sText, " ")
    newText = t
    If InStr(1, t, "-") > 0 Then
      Set f = list.Find(t, , xlValues, xlPart)
      If Not f Is Nothing Then newText = f.Value
    End If
    cad = cad & newText & " "
  Next
  CompleteWords = Trim(cad)
End Function

HOW TO INSTALL UDFs
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use CompleteWords just like it was a built-in Excel function. For example:

Dante Amor
ABC
1EXAMPLEDesired ResultLIST
2Swap from KGLR-EN1 to KGL-EN1-TRTSwap from TSS-KGLR-EN1-TRTT to TSS-KGL-EN1-TRTTSS-KGLR-EN1-TRTT
3Migrate from TGLR-en1 and KGL-pn1 to KGL-EN1-TRTMigrate from TGLR-en1-TRs2 and TSS-KGL-pn1-TR8 to TSS-KGL-EN1-TRTTSS-KGL-EN1-TRT
4TGLR-en1-TRs2
5TSS-KGL-pn1-TR8
6TSS-KGL-EN1-TRT
Sh
Cell Formulas
RangeFormula
B2:B3B2=CompleteWords(A2,$C$2:$C$6)

Hello DanteAmor,

That's awesome, the code works very well. thank you so much for helping me ?

Best Regards,
Amran
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,789
Messages
6,121,605
Members
449,038
Latest member
Arbind kumar

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