tabbytomo
New Member
- Joined
- Jun 23, 2016
- Messages
- 18
Good morning from a very grey UK.
I'm having trouble getting my code to work, I'm trying to look in column M for the value "complete", then copy the entire row to another worksheet. Then, to look at column N for the value "complete" and copy the entire row to another worksheet. Then do the same again in several other worksheets.
The code so far looks at column M and copies the entire row where "complete" is found, but it does not work for column N and I cannot understand why. If I have multiple "complete" rows in column N, it's copying the first one it comes across, then stops. I have a "complete" value in N18, and one in N16, it's only copying across the value in N18 then appearing to stop.
Given this is the first stumbling block, I haven't yet looked at applying it to further worksheets.
Any help greatly appreciated.
I'm having trouble getting my code to work, I'm trying to look in column M for the value "complete", then copy the entire row to another worksheet. Then, to look at column N for the value "complete" and copy the entire row to another worksheet. Then do the same again in several other worksheets.
The code so far looks at column M and copies the entire row where "complete" is found, but it does not work for column N and I cannot understand why. If I have multiple "complete" rows in column N, it's copying the first one it comes across, then stops. I have a "complete" value in N18, and one in N16, it's only copying across the value in N18 then appearing to stop.
Given this is the first stumbling block, I haven't yet looked at applying it to further worksheets.
VBA Code:
Sub CompleteData()
Dim myrange As Range
Sheets("1. Data").Select
Set myrange = Sheets("1. Data").Range("M:M", Range("M" & Rows.Count).End(xlUp))
For Each cell In myrange
If cell.Value = "Complete" Then
lr = Sheets("Completed").Range("A" & Rows.Count).End(xlUp).Row
cell.EntireRow.Copy Destination:=Sheets("Completed").Range("A" & lr + 1)
End If
Next cell
Sheets("1. Data").Select
Set myrange = Sheets("1. Data").Range("N:N", Range("N" & Rows.Count).End(xlUp))
For Each cell In myrange
If cell.Value = "Complete" Then
lr = Sheets("Completed").Range("A" & Rows.Count).End(xlUp).Row
cell.EntireRow.Copy Destination:=Sheets("Completed").Range("A" & lr + 1)
End If
Next cell
End Sub
Any help greatly appreciated.