Copy of Cells if

J

jkrist46

I got help with this in the past. But I need more help. What I need to
do is only copy cells in columns A-H if column 24 has an X in it. This
is what I have so far. Thanks in advance for your help.
Joe

Sub test()
Dim r1 As Range
Dim r2 As Range
Dim L As Long

Worksheets("scheduled").Activate

For L = 1 To 65536
If Cells(L, 24).Value = "X" Then
Set r1 = Worksheets("scheduled").Range("A:H")
Set r2 = Worksheets("test").Range("A:H")
r1.copy r2
Exit Sub
Else
End If
Next

End Sub
 
G

Gary''s Student

Sub test()
Dim r1 As Range
Dim r2 As Range
Dim L As Long

Worksheets("scheduled").Activate
nlastrow = ActiveSheet.UsedRange.Rows.Count

For L = 1 To nlastrow
If Worksheets("scheduled").Cells(L, 24).Value = "X" Then
Worksheets("scheduled").Activate
Set r1 = Worksheets("scheduled").Range(Cells(L, 1), Cells(L, 8))
Worksheets("test").Activate
Set r2 = Worksheets("test").Range(Cells(L, 1), Cells(L, 8))
r1.Copy r2
Else
End If
Next
End Sub

This version only copies specific rows.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top