Extract data from 1 table according to another

hendriksmit

New Member
Joined
Sep 2, 2009
Messages
4
Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
Easy question, i think.<o:p></o:p>
I have 2 tables. One with data containing file names and paths for old and new projects. Another that contains a list of current job numbers. <o:p></o:p>
The file paths contain the project number.<o:p></o:p>
<o:p> </o:p>
What i want to do is create a new table that extract all the file names and paths that contain the project numbers in the project number table.<o:p></o:p>
How do i do this?<o:p></o:p>

Thanks,
Hendrik
 

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.
Welcome to the Board!

Firstly, you probably do not want to extract the results to a table, a query should usually suffice (and will maintain data integrity and the dynamic nature of the database if you do so).

The first question is, do you have the appropriate fields in each table to link the two tables together in a query? If not, you may need to create an intermediate query to extract what you need to link out of a larger fields using text functions like LEFT, RIGHT, MID, and INSTR.

If you need helping accomplishing all this, it would be very helpful if you could post a small sample of the data you have in each table, and what you would like you desired output to look like.
 
Upvote 0
Thanks Joe.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
<o:p>New to this but have some basics. hope this will help to explain.</o:p>
<o:p></o:p>
Table 1 "Files" with file name and path has got field names: ID (auto number), FName, FPath, DateCreated.<o:p></o:p>
<o:p> </o:p>
<TABLE style="BACKGROUND: white; mso-cellspacing: 0cm; mso-yfti-tbllook: 1184" class=MsoNormalTable border=1 cellSpacing=0 cellPadding=0><THEAD><TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BACKGROUND: silver; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0; PADDING-TOP: 0.75pt" colSpan=4>
Files<o:p></o:p>
</TD></TR><TR style="mso-yfti-irow: 1"><TD style="BORDER-BOTTOM: black 1pt inset; BORDER-LEFT: black 1pt inset; PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BACKGROUND: silver; BORDER-TOP: black 1pt inset; BORDER-RIGHT: black 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset black .75pt">
ID<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: black 1pt inset; BORDER-LEFT: black 1pt inset; PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BACKGROUND: silver; BORDER-TOP: black 1pt inset; BORDER-RIGHT: black 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset black .75pt">
FName<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: black 1pt inset; BORDER-LEFT: black 1pt inset; PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BACKGROUND: silver; BORDER-TOP: black 1pt inset; BORDER-RIGHT: black 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset black .75pt">
FPath<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: black 1pt inset; BORDER-LEFT: black 1pt inset; PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BACKGROUND: silver; BORDER-TOP: black 1pt inset; BORDER-RIGHT: black 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset black .75pt">
DateCreated<o:p></o:p>
</TD></TR></THEAD><TBODY><TR style="mso-yfti-irow: 2"><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>
164370<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>2010_AA_AB_AL_EL_A_0104-C08.pdf<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>M:\06019 North Bristol Hospitals P21\06019 Issued\2010 Elevations\<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>
02/09/2009 12:15:43<o:p></o:p>
</TD></TR><TR style="mso-yfti-irow: 3"><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>
164371<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>2010_AA_AB_AL_EL_A_0201-C04.pdf<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>M:\06019 North Bristol Hospitals P21\06019 Issued\2010 Elevations\<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>
02/09/2009 12:15:43<o:p></o:p>
</TD></TR><TR style="mso-yfti-irow: 4"><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>
164372<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>2010_AA_AB_AL_EL_A_0202-C02.dwg<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>M:\06019 North Bristol Hospitals P21\06019 Issued\2010 Elevations\<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>
02/09/2009 12:15:43<o:p></o:p>
</TD></TR><TR style="mso-yfti-irow: 5; mso-yfti-lastrow: yes"><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>
164373<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>2010_AA_AB_AL_EL_A_0202-C02.pdf<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>M:\06019 North Bristol Hospitals P21\06019 Issued\2010 Elevations\<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>
02/09/2009 12:15:43<o:p></o:p>
</TD></TR></TBODY></TABLE>
<o:p> </o:p>
<o:p> </o:p>
Table 2 "tblCurrentProjects" with current projects has got field names: ID (auto number), PrjNumber.<o:p></o:p>
<o:p> </o:p>
<TABLE style="BACKGROUND: white; mso-cellspacing: 0cm; mso-yfti-tbllook: 1184" class=MsoNormalTable border=1 cellSpacing=0 cellPadding=0><THEAD><TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BACKGROUND: silver; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0; PADDING-TOP: 0.75pt" colSpan=2>
tblCurrentProjects<o:p></o:p>
</TD></TR><TR style="mso-yfti-irow: 1"><TD style="BORDER-BOTTOM: black 1pt inset; BORDER-LEFT: black 1pt inset; PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BACKGROUND: silver; BORDER-TOP: black 1pt inset; BORDER-RIGHT: black 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset black .75pt">
ID<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: black 1pt inset; BORDER-LEFT: black 1pt inset; PADDING-BOTTOM: 0.75pt; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BACKGROUND: silver; BORDER-TOP: black 1pt inset; BORDER-RIGHT: black 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset black .75pt">
PrjNumber<o:p></o:p>
</TD></TR></THEAD><TBODY><TR style="mso-yfti-irow: 2"><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>
2<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>08048<o:p></o:p>
</TD></TR><TR style="mso-yfti-irow: 3; mso-yfti-lastrow: yes"><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>
3<o:p></o:p>
</TD><TD style="BORDER-BOTTOM: #d0d7e5 1pt inset; BORDER-LEFT: #d0d7e5 1pt inset; PADDING-BOTTOM: 0.75pt; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0.75pt; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d0d7e5 1pt inset; BORDER-RIGHT: #d0d7e5 1pt inset; PADDING-TOP: 0.75pt; mso-border-alt: inset #D0D7E5 .75pt" vAlign=top>06019<o:p></o:p>
</TD></TR></TBODY></TABLE>
<o:p> </o:p>
So it should look at file path for the project number anywhere in the path and then list the file and the associated path for all the project numbers in table 2.
<o:p> </o:p>
Thanks again.<o:p></o:p>
 
Upvote 0
If the Project number can occur anywhere in the File Path, it is going to make things a bit harder.

If the projext number will always appear in the same spot in the file path, then we can use Text functions to extract it.

Is there any "hard and fast" rule where the project number will occur in the file path?
 
Upvote 0
Joe,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
After studying the data it looks like the number appears just after the “M:\” but it can be 4 or 5 digits long like the example below.<o:p></o:p>
So i think we will cover 99% of all the situations with this assumption.<o:p></o:p>
<o:p> </o:p>
M:\0276 Grove\01 LIVE\CODEBOOK DATABASE\archive\2005-01-13 reports\<o:p></o:p>
M:\05071 Cashel Phase 2\to burn\I Intranet\projectThumb\<o:p></o:p>
<o:p> </o:p>
Hendrik.<o:p></o:p>
 
Upvote 0
So, then in a query, I think we should be able to pull Project Number out of the File Path with a calcuated field like this:

PrjNum: TRIM(MID([FPath],3,5))

So, if you then add all the other fields you need from Table 1 to this query, you can now create a new query where you join this query you just made to Table2 on the Project Number fields.

Does this give you what you want?
 
Upvote 0
Joe,

Exactly what i need. Just changed the 3 to 4 and it was perfect.
Also made the other query and it worked.
Thanks for your help.

Kind regards,
Hendrik
 
Upvote 0
Ah yes, forgot to count the colon, then it would start at 4 not 3. Sorry about that.

Glad we got it to all work out.
 
Upvote 0

Forum statistics

Threads
1,216,474
Messages
6,130,841
Members
449,598
Latest member
sunny_ksy

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