![]() |
Copying an Entire row using an IF Statement
sorry for reposting this
But i need to be able to use the <= = commands with this code is this possible. 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 |
Copying an Entire row using an IF Statement
Could make use of Select Case.
StrComp will return either -1, 0 or 1 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 Select Case StrComp(.Cells(i, 2).Value, str) Case 0, 1 .Rows(i).Copy rng Set rng = rng.Offset(1) End Select Next End With End Sub -- Rob van Gelder - http://www.vangelder.co.nz/excel "Marcus" wrote in message ... sorry for reposting this But i need to be able to use the <= = commands with this code is this possible. 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 |
All times are GMT +1. The time now is 11:23 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com