Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default 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



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If statement to copy an entire row to other worksheet w/ in same b hshayh0rn Excel Worksheet Functions 7 May 1st 09 09:05 PM
Copying/Linking Entire Workbook TomP Excel Discussion (Misc queries) 2 October 6th 08 10:09 PM
copy an entire row IF a statement is true colettey29 Excel Worksheet Functions 1 June 15th 07 06:43 PM
Copying entire worksheets Todd Nelson Excel Discussion (Misc queries) 2 August 31st 05 06:50 PM
Macro for copying entire raw Mac[_5_] Excel Programming 3 November 13th 03 03:09 AM


All times are GMT +1. The time now is 02:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"