ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copying an Entire row using an IF Statement (https://www.excelbanter.com/excel-programming/303254-copying-entire-row-using-if-statement.html)

MArcus

Copying an Entire row using an IF Statement
 
Hi

I want to use the below code to copy an entire row to a
new sheet when a = true. Can anyone help !
Sub YTD_Modifer()

r = 2

a = "1st Quarter Quarter"

Do Until Sheets("Data").Cells(r, 2) = ""

r = r + 1

If Sheets("Data").Cells(r, 2) a Then

copy entire row to a new sheet

End If
Loop
End Sub

Many thanks
Marcus


Rob van Gelder[_4_]

Copying an Entire row using an IF Statement
 
Sub test()
Dim i As Long, rng As Range, str As String

str = "1st Quarter Quarter"
Set rng = Worksheets("Sheet2").Rows(1)

With Worksheets("Data")
For i = 2 To .Cells(Rows.Count, 2).End(xlUp).Row
If StrComp(.Cells(i, 2).Value, str) = 1 Then
.Rows(i).Copy rng
Set rng = rng.Offset(1)
End If
Next
End With
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Marcus" wrote in message
...
Hi

I want to use the below code to copy an entire row to a
new sheet when a = true. Can anyone help !
Sub YTD_Modifer()

r = 2

a = "1st Quarter Quarter"

Do Until Sheets("Data").Cells(r, 2) = ""

r = r + 1

If Sheets("Data").Cells(r, 2) a Then

copy entire row to a new sheet

End If
Loop
End Sub

Many thanks
Marcus




MArcus

Copying an Entire row using an IF Statement
 
I need this code to work with < commands is this possible
-----Original Message-----
Sub test()
Dim i As Long, rng As Range, str As String

str = "1st Quarter Quarter"
Set rng = Worksheets("Sheet2").Rows(1)

With Worksheets("Data")
For i = 2 To .Cells(Rows.Count, 2).End(xlUp).Row
If StrComp(.Cells(i, 2).Value, str) = 1 Then
.Rows(i).Copy rng
Set rng = rng.Offset(1)
End If
Next
End With
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Marcus" wrote in

message
...
Hi

I want to use the below code to copy an entire row to a
new sheet when a = true. Can anyone help !
Sub YTD_Modifer()

r = 2

a = "1st Quarter Quarter"

Do Until Sheets("Data").Cells(r, 2) = ""

r = r + 1

If Sheets("Data").Cells(r, 2) a Then

copy entire row to a new sheet

End If
Loop
End Sub

Many thanks
Marcus



.



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

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