Search Column B for String Found in Column A, Then Copy Matches To Next Column

nickf829

New Member
Joined
Nov 18, 2011
Messages
15
I have 2 columns of data, Column A has a file number and Column B has a list of files that each contain a file number that may or may not appear in Column A.
Before:
Excel Workbook
ABC
1File #File NameFile # Found within Column B
26201File 6201 - Encoding Inv.xml
36202File 6202 - Submission Tag Mismatch.xml
46203File 6203 - Submit after submission deadline.xml
56204File 6204 - Submission Type Tag Inv.xml
66205File 6204 - Submission Type WARNING.xml
76206File 6204 - Submission Type VALID.xml
86207File 6205 - Submission Type Inv.xml
96208File 6206 - Submission Version Tag Inv.xml
106209File 6207 - Submission Version Inv.xml
116210File 6208 - Submission Tag Inv.xml
126211File 6209 - File Audit Data Tag Inv.xml
136212File 6210 - File Number WARNING - length.xml
146213File 6210 - File Number Invalid Data - null.xml
156214File 6210 - File Number WARNING2 - space.xml
16File 6210 - File Number Invalid Data - type.xml
17File 6211 - File Number Tag Inv.xml
18File 6212 - Number of Files - Invalid Data - length.xml
19File 6212 - Number of Files - Invalid Data - null.xml
20File 6212 - Number of Files - VALID - space.xml
21File 6212 - Number of Files - VALID2 - type.xml
22File 6213 - Number of Files Tag Inv.xml
23File 6214 - Create Date Inv WARNING.xml
24File 6214 - Create Date Inv 011-dd-yyyy.xml
25File 9214 - Create Date Inv 02-30-yyyy.xml
26File 8214 - Create Date Inv VALID.xml
27File 7214 - Create Date Inv 06-31-yyyy.xml
Before
#VALUE!
Excel 2010



Any help would be greatly appreciated!
 
Thank you for the help. The formula worked great, but is there a cleaner way to do this in VBA rather than just have the code copy/paste the formula where neccessary?
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type


VoG. I somehow missed that. Blame it on the holidays!

Thank you very much! It did mostly what I needed. I modified it a bit to fit what I'm truely doing, but I'm still stuck on one thing.

"B" is a list of file names, "C" is a list of "A" values that appear in "B". What I need is to have the remaining "B" values that do not contain an "A" value to display "N/A" in the "C" column beside the corresponding "B" filename.

I need this so that I can group all "C" values that don't contain an "A" value and prompt the user to keep or remove these files names as they most likely will not be needed.

Notice in the example, the last three cells of the "C" column are empty, but there are filenames listed in the "B" column. Since these null "C" cells are due to the filenames not containing an "A" column value, I want the corresponding "C" cells to display "N/A"

Example:
Excel Workbook
ABC
1File #File NameFile # Found within Column B
26201File 6201 - Encoding Inv.xml6201
36202File 6202 - Submission Tag Mismatch.xml6202
46203File 6203 - Submit after submission deadline.xml6203
56204File 6204 - Submission Type Tag Inv.xml6204
66205File 6204 - Submission Type WARNING.xml6204
76206File 6204 - Submission Type VALID.xml6204
86207File 6205 - Submission Type Inv.xml6205
96208File 6206 - Submission Version Tag Inv.xml6206
106209File 6207 - Submission Version Inv.xml6207
116210NEED XML(S) CREATED6208 NEED XML(S)
126211File 6209 - File Audit Data Tag Inv.xml6209
136212File 6210 - File Number WARNING - length.xml6210
146213File 6210 - File Number Invalid Data - null.xml6210
156214File 6210 - File Number WARNING2 - space.xml6210
166215File 6210 - File Number Invalid Data - type.xml6210
176216File 6211 - File Number Tag Inv.xml6211
18File 6212 - Number of Files - Invalid Data - length.xml6212
19File 6212 - Number of Files - Invalid Data - null.xml6212
20File 6212 - Number of Files - VALID - space.xml6212
21File 6212 - Number of Files - VALID2 - type.xml6212
22File 6213 - Number of Files Tag Inv.xml6213
23File 6214 - Create Date Inv WARNING.xml6214
24File 6214 - Create Date Inv 011-dd-yyyy.xml6214
25NEED XML(S) CREATED6215 NEED XML(S)
26NEED XML(S) CREATED6216 NEED XML(S)
27File 9214 - Create Date Inv 02-30-yyyy.xml
28File 8214 - Create Date Inv VALID.xml
29File 7214 - Create Date Inv 06-31-yyyy.xml
After Macro is Run
Excel 2007
 
Upvote 0
This is standard Loop inside Loop:
Code:
[color=darkblue]Public[/color] [color=darkblue]Sub[/color] FindUnmatched()
[color=darkblue]Const[/color] csErr     [color=darkblue]As[/color] [color=darkblue]String[/color] = "#N/A"
[color=darkblue]Dim[/color] lLastRowA   [color=darkblue]As[/color] [color=darkblue]Long[/color], lLastRowB [color=darkblue]As[/color] [color=darkblue]Long[/color]
[color=darkblue]Dim[/color] r           [color=darkblue]As[/color] Range
Application.ScreenUpdating = [color=darkblue]False[/color]
lLastRowA = Range("A" & Rows.Count).End(xlUp).Row
lLastRowB = Range("B" & Rows.Count).End(xlUp).Row
[color=darkblue]For[/color] i = 2 [color=darkblue]To[/color] lLastRowA
    [color=darkblue]For[/color] j = 2 [color=darkblue]To[/color] lLastRowB
    [color=darkblue]If[/color] InStr(Range("B" & j).Value, Range("A" & i).Value) > 0 Then _
    Range("C" & j).Value = Range("A" & i).Value
    [color=darkblue]Next[/color] j
[color=darkblue]Next[/color] i
[color=darkblue]On[/color] [color=darkblue]Error[/color] [color=darkblue]Resume[/color] Next
Range("C2:C" & Range("B" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Value = csErr
Application.ScreenUpdating = [color=darkblue]True[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,221,288
Messages
6,159,038
Members
451,533
Latest member
MCL_Playz

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