Matching a value if a code in a table is within another cell

MrBKirk

New Member
Joined
Nov 1, 2023
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
I need a formula that in column F will search and match a table where Column I's value is within Column A and make F egual to the equivalent value in J.
I've tried search, match and Vlookup to no luck.
Eg,
  • I2 is within A2 so B2 should equal to J2
  • I3 is within A5 so B5 should equal to J3
excel problem.PNG
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
AC (cell I2) is in the first three rows. Why is A2 the choice?
 
Upvote 0
AC (cell I2) is in the first three rows. Why is A2 the choice?
Sorry, I was just providing 2 examples, apologies that this was unclear.

Any cells in column A containing the code from column I should make the equivalent B equal to the matching J.
So F3 and F4 should also become J2.
 
Upvote 0
Are the target letters always found in the same position in your course codes? In the example, the two letters you are looking for are all at characters 3 and 4.
 
Upvote 0
Are the target letters always found in the same position in your course codes? In the example, the two letters you are looking for are all at characters 3 and 4.
Characters 3 and 4 are always the start of the course, but unfortunately, 5th characters are also sometimes required. For example, FIC = Food With Imagination and FIT = Personal Fitness. But other times the 5th character no longer relates to the course, for example, 7AHUA7A and 7BHUB7A both should be equal to Humanities and the A & B are not relevant to the course.

Not sure why the person who set it up this way did not make the course codes consistent in format...
 
Upvote 0
Characters 3 and 4 are always the start of the course, but unfortunately, 5th characters are also sometimes required. For example, FIC = Food With Imagination and FIT = Personal Fitness. But other times the 5th character no longer relates to the course, for example, 7AHUA7A and 7BHUB7A both should be equal to Humanities and the A & B are not relevant to the course.

Not sure why the person who set it up this way did not make the course codes consistent in format...
How long is the list of categories? It would be an ungainly but doable "if" if there's not too many more, but otherwise, I see needing some helper columns to extract the relevant bits of the course numbers.
Do the examples I made up for FIT and FIC meet normal courses, or are there extra/missing characters?
CourseCodes.xlsx
AFGHIJ
1SubjectName
21AAC1ACAccounting
31BAC1ARArt
43AAC1BIBiology
50AART2BMBusiness Management
67AHUA7AFICFood with Imagination
77BHUB7AFITPersonal Fitness
84AFIC2AHUHumanities
94AFIT1A
10
11
Sheet2
 
Upvote 0
This is what I came up with. Note: I made up a code for physics to extend the list a little, and a math course number with no math in the list of codes just to see what would happen if the target was not in the list.
Credit for the sumproduct extraction in column L to Excel Search a Cell for a List of Words

CourseCodes.xlsx
AFGHIJKL
1SubjectNameextracted letters
21AAC1AccountingACAccountingAC
31BAC1AccountingARArtAC
43AAC1AccountingBIBiologyAC
50AART2ArtBMBusiness ManagementAR
67AHUA7AHumanitiesFICFood with ImaginationHU
77BHUB7AHumanitiesFITPersonal FitnessHU
84AFIC2AFood with ImaginationHUHumanitiesFIC
94AFIT1APersonal FitnessPHPhysicsFIT
102APH4BPhysicsPH
112AMA4B#VALUE!#VALUE!
Sheet2
Cell Formulas
RangeFormula
F2:F11F2=INDEX($I$2:$J$9,MATCH(L2,$I$2:$I$9,0),2)
L2:L11L2=INDEX($I$2:$I$9,SUMPRODUCT(ISNUMBER(SEARCH($I$2:$I$9,A2))*(ROW($I$2:$I$9)-1)))
 
Upvote 0
I am only on a phone at the moment so can't give you the exact formula but based on your response to @Asbestos_Jen in post 5, how about a vlookup on mid(a2,3, 3), wrap it in iferror with the error condition being a vlookup on mid(a2 3,2).
ie if lookup on 3 characters fails try 2.
 
Upvote 0
Solution
As per Alex's suggestion, you could try this.

BTW, I suggest that you investigate XL2BB for providing sample data to make it easier for helpers by not having to manually type out sample data to test with.

23 11 03.xlsm
AFGHIJ
1SubjectName
21AAC1AccountingACAccounting
31BAC1AccountingARArt
43AAC1AccountingBIBiology
50AART2ArtBMBusiness Management
67AHUA7AHumanitiesFICFood with Imagination
77BHUB7AHumanitiesFITPersonal Fitness
84AFIC2AFood with ImaginationHUHumanities
94AFIT1APersonal FitnessPHPhysics
102APH4BPhysics
112AMA4B#N/A
Lookup Code
Cell Formulas
RangeFormula
F2:F11F2=IFNA(VLOOKUP(MID(A2,3,3),I$2:J$9,2,0),VLOOKUP(MID(A2,3,2),I$2:J$9,2,0))
 
Upvote 0
This is what I came up with. Note: I made up a code for physics to extend the list a little, and a math course number with no math in the list of codes just to see what would happen if the target was not in the list.
Credit for the sumproduct extraction in column L to Excel Search a Cell for a List of Words

Thanks Asbestos_Jen, those formulas are fantastic, I will certainly keep them in mind for future reference. Unfortunately, there are almost 400 lines of unique subjects and over 50 in the reference table. 70 rows returned errors, more due to idiosyncrasies with the formatting of the subject codes than your formula though.

I am only on a phone at the moment so can't give you the exact formula but based on your response to @Asbestos_Jen in post 5, how about a vlookup on mid(a2,3, 3), wrap it in iferror with the error condition being a vlookup on mid(a2 3,2).
ie if lookup on 3 characters fails try 2.

Thanks so much Alex! worked almost perfectly, with only one issue with 0PHO = Photography, 0PHY = Physics and 3PH = Physics resulting in all three becoming physics, but I'm just going to have the original creator use 3PHY in the future to rectify this problem.

As per Alex's suggestion, you could try this.

BTW, I suggest that you investigate XL2BB for providing sample data to make it easier for helpers by not having to manually type out sample data to test with.

I'll certainly look into XL2BB and give it a try in the future, wasn't aware of it as I just created the account for this problem. Thanks for the suggestion and apologies for the inconvenience everyone!

Thank you all again for your input and support! This will save us a lot of manual processing!
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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