Code To Look For Number On Sheet 2, When Found Insert Row & Add Number Next To It

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,751
Office Version
  1. 365
Platform
  1. Windows
Hi, I have sheet 1 with 3 columns of data. The code needs to look for the number that is in column C on sheet 1 on sheet 2. When it is found I need a row inserted below on sheet 1 with the numbers that are next to that number on sheet 2. The example below will explain better.

Excel Workbook
ABC
109AR145161001EFAR8008
1110AR145161001ECAR5012
1211AR145161001EXAR9001
Sheet1



Excel Workbook
ABCD
21EFAR8008EMG002Gasket
32ECAR5012EMG002Gasket
43ECAR5012EMG171Gasket
54EXAR9001EMR031Rubber
65EXAR9001EMR113Rubber
76EXAR9001EMR130Rubber
Sheet2



Excel Workbook
ABCD
109AR145161001EFAR8008
119AR145161001EMG002Gasket
1210AR145161001ECAR5012
1310AR145161001EMG002Gasket
1410AR145161001EMG171Gasket
1511AR145161001EXAR9001
1611AR145161001EMR031Rubber
1711AR145161001EMR113Rubber
1811AR145161001EMR130Rubber
Sheet1 Result


As you can see in the 3rd table is the result on sheet 1. It has found wherever the number is on sheet 2 and add the data that is next to it in columns C & D on sheet 2. Please help and can get big brownie points from my Director!!!
 
Forget the part where I said it copied some rows several hundred times I used it on the wrong file, but it does only about 10%. I think the first code is nearer the mark but it just keeps freezing.
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Ok, this isn't going to work using Excel.
You have 73k records on sheet1 and 19k on sheet2.
We need a database.

Open Access, with a blank database.
Click the ExternalDate tab and select Excel as the source.
Browse for the file and click OK.
Select Sheet1 as the source and click Next.
Tick first row contains column headers and click next.
next
next
next
finish
close.

Repeat and import sheet2.


Select the Create tab.
Select Other=> Query Design
Add Sheet1 and Sheet2 tables and close the dialog box.

Select the PART in sheet1 and drag it over to the PART in sheet2 - this is the relationship between the tables.
Double click on
Sheet1 - index
Sheet1 - system code
Sheet1 - part
Sheet2 - CatCode
Sheet2 - Desc

As you double click you will see these populate the table below the split screen.

On the Results tab click Run, the red exclamation mark icon.

You can right click the Query and export the results.
 
Last edited:
Upvote 0
That does work but not quite as I need. I need the parts underneath whereas the database puts them in a column next to it.
 
Last edited:
Upvote 0
This is th result using access

INDEXSYSTEM CODESheet1_PartSheet2_PartDesc
1ANAMB171001EXAN2020EMB023SPRING
2ANAMB171001EXAN2020EMCLAMP48mm
3ANAMB171001EXAN2020EMCP024MANIFOLD CLAMP
4ANAMB201001EXAN2020EMB023SPRING
5ANAMB201001EXAN2020EMCLAMP48mm
6ANAMB201001EXAN2020EMCP024MANIFOLD CLAMP

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>

But what I need is

`SYSTEM CODESheet1_PartSheet2_Part
1ANAMB171001EXAN2020
2ANAMB171001EMB023SPRING
3ANAMB171001EMCLAMP48mm
3ANAMB171001EMCP024MANIFOLD CLAMP
4ANAMB201001EXAN2020
5ANAMB201001EMB023SPRING
6ANAMB201001EMCLAMP48mm
6ANAMB201001EMCP024MANIFOLD CLAMP

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Update: I did run the code and it did complete but it took most of the night with a few errors which I corrected manually so for now I have the result I need. I would however appreciate it if you can think of a way to speed up the code as it will be needed to be used quite a lot in the future. Thanks for your time Bertie.
 
Upvote 0
Hi Darren,
I am away for Easter and it will be Sunday evening at the earliest before I can look a your stuff again.

Have you tried putting the result of the database query into a pivot table?

Anyway, I assume the database query has compacted your data down to a more manageable size. You have my email address. Can you post me a sample of data from the database query.
 
Upvote 0

Forum statistics

Threads
1,216,114
Messages
6,128,910
Members
449,478
Latest member
Davenil

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