Any VBA or Formula to find name and past in specified column

Joined
Aug 14, 2022
Messages
6
Office Version
  1. 2019
Platform
  1. Windows
Hello everyone,
Wish you will all be happy and healthy and wana thanks in advance to all the champions.

Problem:
i have an excel sheet which i prepared daily, weakly and monthly having column names Date, Reference, Customer/vender, and description. i also have a column name unique names.

what i want?
I want a VBA code that will take the name from unique name list and find the name in description. If name found in description then write this name in Customer/Vender column name otherwise write nothing/leave blank.

again very thanks to all of you!

Regards

Date for seperating customers.xlsx
ABCDEFGHIJ
1Posed DateReferencCustomer/venderDescriptionAmountUnique name
21-Jan-22AC-KHALIFA SONS-BANK DRAFT2500tanzeel
32-Jan-22PURCHASE FROM MALIK & SONS1200khalifa
44-Jan-22TRANSFER TO FARISHTA1500farishta
56-Jan-22JOHN MICK PENALITY PAID2500john mick
68-Jan-22SALE OF FUEL TO KASHIF2000suleman
712-Jan-22FEE RECEIVED FROM NAZIR AHMED2500lesco
823-Jun-22CLEANING FEE PAID TO TANZEEL1000
928-Jun-22TUTION FEE PAID TO SULEMAN500
1031-Jul-22TRANSFER TO KAMAL200
1130-Jul-22ELECTRICITY PAID TO LESCO150
1218-Jul-22WATER CHARGES PAID TO HELMON89
1322-Mar-22money transfer to tanzeel12
Sheet1
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Here's some untested code that you can try. Note that it assumes Unique names will always be lower case as in your posted example.
Warning this will assign the customer/vendor name john mick to a description that's like JOHN MICKSON PAID because it contains JOHN MICK.
VBA Code:
Sub AddToCustVendList()
'Assumes unique name will always be in lower case
Dim Rdes As Range, Ru As Range, ct As Long, Vdes, Vu, Vout, i As Long, j As Long
Set Rdes = Range("D2:D" & Cells(Rows.Count, "D").End(xlUp).Row): Vdes = Rdes.Value
Set Ru = Range("J2:J" & Cells(Rows.Count, "J").End(xlUp).Row): Vu = Ru.Value
ReDim Vout(1 To UBound(Vdes), 1 To 1)
For i = 1 To UBound(Vdes, 1)
    For j = 1 To UBound(Vu, 1)
        If LCase(Vdes(i, 1)) Like "*" & Vu(j, 1) & "*" Then
            ct = ct + 1
            Vout(i, 1) = Vu(j, 1)
            GoTo Nx
        Else
            Vout(i, 1) = ""
        End If
    Next j
Nx:
Next i
If ct > 0 Then
    Rdes.Offset(0, -1).Value = Vout
    MsgBox "Finished- " & ct & " customer/vendor names added"
Else
    MsgBox "Finished - no customer/vendor names added"
End If
End Sub
 
Upvote 0
Solution
Does it need to be vba?

22 08 21.xlsm
CDJ
1Customer/venderDescriptionUnique name
2khalifaAC-KHALIFA SONS-BANK DRAFTtanzeel
3 PURCHASE FROM MALIK & SONSkhalifa
4farishtaTRANSFER TO FARISHTAfarishta
5john mickJOHN MICK PENALITY PAIDjohn mick
6 SALE OF FUEL TO KASHIFsuleman
7 FEE RECEIVED FROM NAZIR AHMEDlesco
8tanzeelCLEANING FEE PAID TO TANZEEL
9sulemanTUTION FEE PAID TO SULEMAN
10 TRANSFER TO KAMAL
11lescoELECTRICITY PAID TO LESCO
12 WATER CHARGES PAID TO HELMON
13tanzeelmoney transfer to tanzeel
Insert name
Cell Formulas
RangeFormula
C2:C13C2=IFNA(LOOKUP(9^9,SEARCH(J$2:J$7,D2),J$2:J$7),"")


If it does need to be vba then we can still utilise that formula within the vba.

VBA Code:
Sub InsertNames()
  With Range("C2:C" & Range("D" & Rows.Count).End(xlUp).Row)
    .Formula = Replace("=IFNA(LOOKUP(9^9,SEARCH(J$2:J$#,D2),J$2:J$#),"""")", "#", Range("J" & Rows.Count).End(xlUp).Row)
    .Value = .Value
  End With
End Sub

Both of my suggestions come with the same warning that @JoeMo described.
Warning this will assign the customer/vendor name john mick to a description that's like JOHN MICKSON PAID because it contains JOHN MICK.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,862
Members
449,052
Latest member
Fuddy_Duddy

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