COPYING Rows to Another Worksheet Based on Criteria - Problem with Code - HELP is appreciated!

kescco

Board Regular
Joined
Sep 14, 2009
Messages
174
WORKSHEET 1 = MAIN
WORKSHEET 2 = BINS

Copying all rows in BINS with 999 in Column C to MAIN.

Problem is that my 999 rows start in Row 1 of BINS and thus the top
entry is being left out (works from the bottom). For now, I have added a
blank row at the top. Is there a better way to fix this?

All help is appreciated.


PHP:
Dim lr2 As Long, r As Longlr = Sheets("Bins").Cells(Rows.Count, "C").End(xlUp).Row
lr2 = Sheets("Main").Cells(Rows.Count, "F").End(xlUp).Row
For r = lr To 2 Step -1
    If Sheets("Bins").Range("C" & r).Value = "999" Then
        Sheets("Bins").Rows(r).Copy Destination:=Sheets("Main").Range("A" & lr2 + 1)
        lr2 = Sheets("Main").Cells(Rows.Count, "F").End(xlUp).Row
    End If
Next r
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi kesco,

Just change the 2 in this line of code...

Rich (BB code):
For r = lr To 2 Step -1

...to 1

Note you don't have to loop backwards when copying only really when you are deleting or moving rows.

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,203,082
Messages
6,053,420
Members
444,662
Latest member
AaronPMH

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