ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   Copy of Cells if (https://www.excelbanter.com/new-users-excel/80972-copy-cells-if.html)

jkrist46

Copy of Cells if
 
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

Gary''s Student

Copy of Cells if
 
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.
--
Gary''s Student


"jkrist46" wrote:


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


--
jkrist46



All times are GMT +1. The time now is 01:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com