Macro to copy row based on TWO cell values

uncleslinky

New Member
Joined
Mar 31, 2009
Messages
47
Hi,

Is it possible to have a macro to copy an entire row to the bottom of another worksheet based on column G being "N" and column H being "YES". I would like to copy the data from a sheet and called "Hours" and paste it into a sheet called "DONE"

If there is no data I would like the macro to either end or have a pop up state that "all rows have been copied"

I have tried using auto filter however when copying data the header is always included, which I do not want.

Thanks
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try this

Code:
Sub CopyRows()
Dim LR As Long, i As Long, j As Long
With Sheets("Hours")
    LR = .Range("G" & Rows.Count).End(xlUp).Row
    For i = 2 To LR
        If .Range("G" & i).Value = "N" And .Range("H" & i).Value = "YES" Then
            j = j + 1
            .Rows(i).Copy Destination:=Sheets("DONE").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End If
    Next i
End With
MsgBox "Done:" & vbNewLine & j & " rows copied", vbInformation
End Sub
 
Upvote 0
hi,

that's great, thanks!
is there a way to ammend this code so that instead of copying the entire row it only copies columns A:F?

thanks again!
 
Upvote 0
Try

Rich (BB code):
Sub CopyRows()
Dim LR As Long, i As Long, j As Long
With Sheets("Hours")
    LR = .Range("G" & Rows.Count).End(xlUp).Row
    For i = 2 To LR
        If .Range("G" & i).Value = "N" And .Range("H" & i).Value = "YES" Then
            j = j + 1
            .Range("A" & i).Resize(, 6).Copy Destination:=Sheets("DONE").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End If
    Next i
End With
MsgBox "Done:" & vbNewLine & j & " rows copied", vbInformation
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,604
Messages
6,179,857
Members
452,948
Latest member
UsmanAli786

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