-
VBA to copy row if cells contain value
Hi guys and girls...
I have the following set of results in excel:
R01 |
4940 |
19-Jan-15 |
R002 |
5184 |
23-Feb-15 |
R001 |
5362 |
27-Mar-15 |
R002 |
5429 |
01-May-15 |
R01 |
5434 |
07-Aug-15 |
R2 |
5434 |
09-Nov-15 |
R001 |
5434 |
09-Feb-16 |
R001 |
5434 |
09-May-16 |
I need a VBA code to look for the cells that have a "1" in and copy them to one sheet, and copy the cells with a "2" in to another....
I've tried using:
For Each Cell In Sheets("3").Range("A:A")
If Cell.Value = "R001" Then
MatchRow = Cell.Row
Rows(MatchRow & ":" & MatchRow).Select
Selection.Copy
Sheets("4").Select
ActiveSheet.Rows(MatchRow + 1).Select
ActiveSheet.Paste
Sheets("4").Select
End If
Next
But this just finds the first row of R0001 and keeps copying the first row rather than moving on and copying the second... so i end up with :
3 times rather than all 3 R0001.... It also doesn't help grab the other "1"'s
Any help would be massively appreciated...
Cheers
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules