Macro to copy rows to new worksheet without repeating itself

wling1

New Member
Joined
Aug 26, 2014
Messages
3
Hi, I have searched through the forums and found a macro that will search one column for a word, copy the row, and paste it onto a new worksheet:

Code:
[COLOR=#333333][I]Sub COPYROW()[/I][/COLOR]
[COLOR=#333333][I]Dim rcnt As Long, result As Long[/I][/COLOR]

[COLOR=#333333][I]rcnt = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row[/I][/COLOR]
[COLOR=#333333][I]result = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row[/I][/COLOR]

[COLOR=#333333][I]For i = 2 To rcnt[/I][/COLOR]
[COLOR=#333333][I]If Sheets("Sheet1").Range("C" & i).Value = [/I][/COLOR][COLOR=red][I]"condition in col C"[/I][/COLOR][COLOR=#333333][I] Then[/I][/COLOR]
[COLOR=#333333][I]result = result + 1[/I][/COLOR]
[COLOR=#333333][I]Sheets("Sheet1").Rows(i & ":" & i).Copy (Sheets("Sheet2").Rows(result & ":" & result))[/I][/COLOR]
[COLOR=#333333][I]End If[/I][/COLOR]
[COLOR=#333333][I]Next[/I][/COLOR]
[COLOR=#333333][I]End Sub[/I][/COLOR]

This code works great, except if I run this macro again, it will re-copy and past what's already been copied right below where it was first pasted. I would like it where if new information was added to Sheet1 then it would just copy the new information and paste it onto Sheet2. Is this possible?

Another thing is, when it copies the rows, it pastes them in the same order on the new page, for example, if it copies rows 3 and 5, it'll post them on sheet2 in rows 3 and 5, and I would like it to post in rows 2 and 3.

Any help is greatly appreciated!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,216,096
Messages
6,128,807
Members
449,468
Latest member
AGreen17

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