Copy & Insert Row Based on 'Match' result - VBA

Cat129

Board Regular
Joined
Oct 20, 2012
Messages
96
I have 2 sheets within the workbook

MATCH is used on the first sheet to give me the row number of each part

I then want to copy and insert that row into sheet 2 at the row number specified by match

Any ideas? Is this possible?

Thanks,
Cat
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi Cat. Are U sure U want to insert the row or just copy it? Here's code for the insert match row to sheet2 then copy match row from sheet1 to sheet2 at same row number (after row has been inserted). HTH. Dave
Code:
Dim Rownumber As Integer
Rownumber = 2 ' insert row number generated by match
Sheets("Sheet2").Cells(Rownumber, 1).Insert Shift:=xlDown
Sheets("Sheet1").Range("A" & Rownumber).EntireRow.Copy _
                Destination:=Sheets("Sheet2").Range("A" & Rownumber)
 
Upvote 0
Hi Cat. Are U sure U want to insert the row or just copy it? Here's code for the insert match row to sheet2 then copy match row from sheet1 to sheet2 at same row number (after row has been inserted). HTH. Dave
Code:
Dim Rownumber As Integer
Rownumber = 2 ' insert row number generated by match
Sheets("Sheet2").Cells(Rownumber, 1).Insert Shift:=xlDown
Sheets("Sheet1").Range("A" & Rownumber).EntireRow.Copy _
                Destination:=Sheets("Sheet2").Range("A" & Rownumber)

Hey Thanks for the above, How does the code know what the row number is that has been generated by match.

Sheet 2 is the master. The way the macro works up to this point is is does a whole heap of comparisons to decide if parts from Sheet 1 have been removed / updated revisions / updated descriptions etc compared to sheet 2. It then looks at sheet two updates all the values to the new ones and then, does a load more comparisons to determine which parts are new parts and need to be added to sheet 2.

It does a match function to find the row location of the items on sheet 2 within sheet 1.

The Match function is to keep items in the same order, so if something was added to assembly 23, say on row 244 (Sheet 1) it would input that row into row 244 on sheet 2, thus keeping everything where it should.

I really hope that makes sense and I haven't confused things.

Thanks,
Cat
 
Upvote 0
So U really don't want to insert a row on sheet2, U want to replace the existing sheet2 row with the same sheet1 row? Dave
 
Upvote 0

Forum statistics

Threads
1,215,226
Messages
6,123,734
Members
449,116
Latest member
alexlomt

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