Check Cell Content Against Range & Print Matching Results

nparkinglot

New Member
Joined
Jul 27, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I've found a lot of posts that get really close to what I'm trying to do but none that seem to cover key parts that I'm trying to suss out. I'm still basically a newbie so maybe this is obvious and I'm just missing it.

I'm trying to either create a formula or a vba module that will check the contents of a cell for a partial, exact match from a range on a separate worksheet, and if it finds a match, print that match in a cell in a separate column on the same row as the original cell. Then if I found a formula I'd drag it down the column and create a macro or if it's vba I'd need it to loop back around and do the next cell down.

The reason for the 'partial, exact' is I'm working with data output from a joint outlook calendar and I have very little control over what exactly people are putting in the column in question. For example, I might have 'AD- Off-Desk' in A2, I need it to find 'AD' from the range on the other worksheet ( StaffTaskData D2:D34) and print that in a new column (G, beginning row 2). I also might have 'AAD - PTO', here I need it to find 'AAD' in the range, not 'AD'.

Any help is greatly appreciated.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I can probably help. Is there always a dash after the part of the text to use for the lookup?

If possible, consider sharing relevant data use using Mr Excel's excellent XL2BB addin that enables you to post a portion of a worksheet. See XL2BB - Excel Range to BBCode for details. Post fake-but-realistic data for the best response.
 
Upvote 0
Is it always the leftmost characters that you need to "match"? Please provide some examples of how the match would work.
 
Upvote 0
Does this accomplish what you need?

Do Partial Match.xlsm
ABCDEFG
2AADAD- Off-DeskAAD - PTO
3BAC -
4QAC - Back
5ADD- Bill
6MP- Test
7QRT - 999
8BBB- Desk
9AAD - PTO
10BQ - Up Desk
StaffTaskData
Cell Formulas
RangeFormula
G2G2=IFERROR( INDEX($D$2:$D$10, MATCH(A2& "*", $D$2:$D$10,0)), "not found")


In the example MATCH looks in the range of values to see if there is a "partial match." Wildcard character * means "any other characters". If there IS a "partial match" then INDEX takes the result from MATCH and "selects" the respective value in the cell where "partial match" was found. If the string sought is not found then the MATCH function returns an error, hence the IFERROR function which returns "not found" if there is no match.
 
Last edited:
Upvote 0
This example breaks the task into the two worksheets as you specified.

Do Partial Match.xlsm
ABCDEFG
1InputResult
2APnot found
3AADAAD - PTO
4BBBBB- Desk
5QQQnot found
6ABCnot found
7ADAD- Off-Desk
8QRTQRT - 999
9RRRnot found
10MPMP- Test
11QACQAC - Back
Main
Cell Formulas
RangeFormula
G2:G11G2=IF(A2 = "", "", IFERROR( INDEX(StaffTaskData!$D$2:$D$10, MATCH(A2& "*", StaffTaskData!$D$2:$D$10,0)), "not found") )


Do Partial Match.xlsm
D
1
2AD- Off-Desk
3BAC -
4QAC - Back
5ADD- Bill
6MP- Test
7QRT - 999
8BBB- Desk
9AAD - PTO
10BQ - Up Desk
StaffTaskData
 
Upvote 0
This example breaks the task into the two worksheets as you specified.

Do Partial Match.xlsm
ABCDEFG
1InputResult
2APnot found
3AADAAD - PTO
4BBBBB- Desk
5QQQnot found
6ABCnot found
7ADAD- Off-Desk
8QRTQRT - 999
9RRRnot found
10MPMP- Test
11QACQAC - Back
Main
Cell Formulas
RangeFormula
G2:G11G2=IF(A2 = "", "", IFERROR( INDEX(StaffTaskData!$D$2:$D$10, MATCH(A2& "*", StaffTaskData!$D$2:$D$10,0)), "not found") )


Do Partial Match.xlsm
D
1
2AD- Off-Desk
3BAC -
4QAC - Back
5ADD- Bill
6MP- Test
7QRT - 999
8BBB- Desk
9AAD - PTO
10BQ - Up Desk
StaffTaskData
This example breaks the task into the two worksheets as you specified.

Do Partial Match.xlsm
ABCDEFG
1InputResult
2APnot found
3AADAAD - PTO
4BBBBB- Desk
5QQQnot found
6ABCnot found
7ADAD- Off-Desk
8QRTQRT - 999
9RRRnot found
10MPMP- Test
11QACQAC - Back
Main
Cell Formulas
RangeFormula
G2:G11G2=IF(A2 = "", "", IFERROR( INDEX(StaffTaskData!$D$2:$D$10, MATCH(A2& "*", StaffTaskData!$D$2:$D$10,0)), "not found") )


Do Partial Match.xlsm
D
1
2AD- Off-Desk
3BAC -
4QAC - Back
5ADD- Bill
6MP- Test
7QRT - 999
8BBB- Desk
9AAD - PTO
10BQ - Up Desk
StaffTaskData
I think this almost hits the nail exactly on the head, I just need it to return the partial string it was looking for, not the entire string in the cell. (Just return 'AAD', not 'AAD - PTO'. But that might actually make it simpler, right? Because I could use an IF statement and have it return the string in the target cell if true? I'm having trouble figuring out where that would actually go in this formula though.

Theoretically, yes the part of the string should always be on the left.

I really appreciate your help! This is my first time using this forum.
 
Upvote 0
I want to assist but I'm a bit confused. If the string searched for is AD and there is a string with ADD - Test just return the AD part or ADD? If searching for AAD and there is an entry AAD- Other just return AAD no dash. What if it finds AADD - More? Should it return "no match" if no match is found? What about AADDP - Stuff.

Hopefully you provide some more examples of the string sought and the result wanted, so I understand.

You can provide data using Mr Excel's excellent XL2BB addin that enables you to post a portion of a worksheet. See XL2BB - Excel Range to BBCode for details. That is how I posted my attempt at a solution.

Depending on what you are looking for this may require a VBA solution. I hope that is ok.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
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