If cell contains copy row... but more complicated

HotLanta

Board Regular
Joined
Nov 3, 2005
Messages
176
Hi,

I started putting this one together but it became too complicated for me as I have two conditions...

On sheet "Sheet 1" if the cell in column I contains "L" then copy that row to sheet "LH" and then cycle through all the next rows until complete.
But also,
On sheet "Sheet 1" if the cell in column I contains "R" then copy that row to sheet "RH" and then cycle through all the next rows until complete.

I could do the one condition, but not two.

Thanks for any help!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
How about
Code:
Sub HotLanta()
    With Sheets("Sheet1")
        .Range("A1:I1").AutoFilter 9, "*L*"
        .AutoFilter.Range.Offset(1).EntireRow.Copy Sheets("LH").Range("A" & Rows.Count).End(xlUp).Offset(1)
        .Range("A1:I1").AutoFilter 9, "*R*"
        .AutoFilter.Range.Offset(1).EntireRow.Copy Sheets("RH").Range("A" & Rows.Count).End(xlUp).Offset(1)
        .AutoFilterMode = False
    End With
End Sub
 
Upvote 0
If you have a large range with data, autofilter (see Fluff's code) will be faster.
You can extend it as much as you want as long as the arrays have the same amount of data (i.e. each 12 items)
Code:
Sub Maybe()
Dim vArr, shArr, c As Range, i As Long
vArr = Array("L", "R")
shArr = Array("LH", "RH")
    For Each c In Range("I1:I" & Cells(Rows.Count, "I").End(xlUp).Row)
        For i = LBound(vArr) To UBound(vArr)
            If c.Value = vArr(i) Then c.EntireRow.Copy Sheets(shArr(i)).Cells(Rows.Count, "A").End(xlUp).Offset(1)
        Next i
    Next c
End Sub
 
Upvote 0
Fluff and jolivanes,

Thank you both for your help, I tried Fluff's first and it has worked perfectly. (If it isn't broken - don't fix it). I will bookmark this and try jolivanes code if I run in to trouble later. Thanks again.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,377
Messages
6,119,182
Members
448,872
Latest member
lcaw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top