Vba to look if the first 4 numbers of a string matches the values in another column

raphagcwill

New Member
Joined
Jan 12, 2016
Messages
41
Hello!

Hope you guys doing great and perhaps can help me out.

What I have

In column C, starting from row 10 i have thousants of different combination of numbers “transaction numbers”

I column T, starting from row 2 i have a list with thousand of unique 4-digit numbers “client numbers”. Their names are present in the row to the right, column U

What I need

I would like VBA to match the first 4 digits of Column C (from C10 to lastrow) with the values in Column T.

If match is true, then copy the equivalent client name (found in column U) to column V

If match is false, then insert text “not our client” in column V

Thanks in advance!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try one of formula at column F or G:
Book1
ABCDEFGH
1
2A111A129824B0001B0003B0019
3A112A121836B0002B0010B0011
4A113A111630B0003B0016B0001
5A114A124428B0004B0013B0014
6A115A127353B0005B0007B0017
7A116A126460B0006B0017B0016
8A117A115363B0007B0018B0005
9A138A119704B0008 B0009
10A119A120600B0009B0008B0010
11A120A112628B0010B0009B0002
12A121A125799B0011B0002 
13A122A128326B0012B0014B0018
14A123A114253B0013B0015B0004
15A124A122789B0014B0004B0012
16A145A123514B0015 B0013
17A126A113476B0016B0006B0003
18A127A116248B0017B0005B0006
19A128A117246B0018B0012B0007
20A129A118517B0019B0001 
21
22
Sheet3
Cell Formulas
RangeFormula
F2:F20F2=IFNA(INDEX($E$2:$E$20,MATCH(A2&"*",$D$2:$D$20,0)),"")
G2:G20G2=IFNA(INDEX($E$2:$E$20,MATCH(LEFT(D2,4),$A$2:$A$20,0)),"")
 
Upvote 0
What I have
In column C, starting from row 10 i have thousants of different combination of numbers “transaction numbers”
I column T, starting from row 2 i have a list with thousand of unique 4-digit numbers “client numbers”. Their names are present in the row to the right, column U
What I need
I would like VBA to match the first 4 digits of Column C (from C10 to lastrow) with the values in Column T.
If match is true, then copy the equivalent client name (found in column U) to column V
If match is false, then insert text “not our client” in column V

Isn't this what you are describing?

21 10 24.xlsm
CSTUV
1
2A111Name 1Name 1
3A112Name 2Name 2
4A113Name 3Name 3
5A114Name 4Name 4
6A115Name 5Name 5
7A116Name 6Name 6
8A117Name 7Name 7
9A138Name 8not our client
10A129824A119Name 9Name 9
11A121836A120Name 10Name 10
12A111630A121Name 11Name 11
13A124428A122Name 12Name 12
14A127353A123Name 13Name 13
15A126460A124Name 14Name 14
16A115363A145Name 15not our client
17A119704A126Name 16Name 16
18A120600A127Name 17Name 17
19A112628A128Name 18Name 18
20A125799A129Name 19Name 19
21A128326
22A114253
23A122789
24A123514
25A113476
26A116248
27A117246
28A118517
29
Check Names
Cell Formulas
RangeFormula
V2:V20V2=IFNA(IF(MATCH(T2&"*",C$10:C$10000,0),U2),"not our client")
 
Last edited:
Upvote 0
Solution
Hello Peter!

Thank you very much for taking the time to help me.

It was exactly what I described. Your solution was spot on and i did not need to chance anything in the formula.

Have a great day!
 
Upvote 0
You're welcome. Thanks for the confirmation. :)
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

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