VBA copy and paste rows

Newbie76

New Member
Joined
Oct 6, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm new to VBA, I have a code which is below, the code works great if my data start in column A, but my data start in column D row 2. How do I change it for column D?
VBA Code:
Private Sub CommandButton1_Click()

For i = 2 To 25

If Worksheets("Today").Cells(i, 9).Value > 2 Then

Worksheets("Today").Rows(i).Copy

Worksheets("Completed").Activate

b = Worksheets("Completed").Cells(Rows.Count, 1).End(xlUp).Row

Worksheets("Completed").Cells(b + 1, 1).Select

ActiveSheet.Paste
Worksheets("Today").Rows(i).ClearContents
End If
Next
End sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Do columns A, B and C contain any headers in row 1 or any data or are they blank?
 
Upvote 0
Try:
VBA Code:
Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Dim lCol As Long, srcWS As Worksheet, desWS As Worksheet
    Set srcWS = Sheets("Today")
    Set desWS = Sheets("Completed")
    With srcWS
        lCol = .Cells(1, Columns.Count).End(xlToLeft).Column
        .Range("I1").AutoFilter 9, ">2"
        .AutoFilter.Range.Offset(1, 3).Copy desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1)
        .Range("I1").AutoFilter
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,883
Messages
6,175,167
Members
452,615
Latest member
bogeys2birdies

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