Copy only selected rows

harry211

New Member
Joined
Mar 7, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi!
My macro looks like this:

Sub copydata ()
Sheets ("Template"). Select
lr = Cells.Find ("*", Cells (1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False) .Row
Range ("A3: R" & lr) .Copy
Sheets ("List"). Select
lrTarget = Cells.Find ("*", Cells (1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False) .Row
Cells (lrTarget + 1, 1) .Select
Selection.PasteSpecial Paste: = xlPasteValues, Operation: = xlNone, SkipBlanks _
: = False, Transpose: = False
End Sub

It works fine with copying all lines to the "List" tab. I need to modify the code, which will copy only those rows where in the R column (the "STATUS" column) the status is "Done".
1646681008301.png


Thanks in advance for any help!
J.
 
One more thing, I need to paste values only :)
Try this Harry:

VBA Code:
Option Explicit
Sub harry211_V4()
    Dim ws1 As Worksheet, ws2 As Worksheet, lr As Long
    Set ws1 = Sheets("Template")
    Set ws2 = Sheets("List")
    lr = ws2.Cells(Rows.Count, 1).End(3).Row
    If lr = 1 Then lr = 2
    
    With ws1.Range("A2").CurrentRegion
        .Columns.Hidden = False
        .AutoFilter 18, "Done"
        .Offset(1).Resize(.Rows.Count - 1).Copy
            ws2.Range("A" & lr).PasteSpecial xlPasteValues
            Application.CutCopyMode = False
        .AutoFilter
    End With
    ws1.Range("C:F").EntireColumn.Hidden = True
End Sub
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
oh and one last thing. The code overwrites the last row instead of pasting the data into the first free one
VBA Code:
Option Explicit
Sub harry211_V5()
    Dim ws1 As Worksheet, ws2 As Worksheet, lr As Long
    Set ws1 = Sheets("Template")
    Set ws2 = Sheets("List")
    lr = ws2.Cells(Rows.Count, 1).End(3).Row
    'If lr = 1 Then lr = 2
    
    With ws1.Range("A2").CurrentRegion
        .Columns.Hidden = False
        .AutoFilter 18, "Done"
        .Offset(1).Resize(.Rows.Count - 1).Copy
            ws2.Range("A" & lr + 1).PasteSpecial xlPasteValues
            Application.CutCopyMode = False
        .AutoFilter
    End With
    ws1.Range("C:F").EntireColumn.Hidden = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

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