Michael515
Board Regular
- Joined
- Jul 10, 2014
- Messages
- 136
Hi Y'all,
The code below inserts a matching function, to match cell values from one cell in Sheet1 to an array in Sheet 2. Then I created a loop that if the Match value > 0, to then take the whole row of that "i" value and paste into sheet 3. For some reason my loop isn't looking at all the M & "i" cells because I have two cells that have a value greater than 0. I'd appreciate you're help, especially because I feel like I'm right there. Thanks again!
The code below inserts a matching function, to match cell values from one cell in Sheet1 to an array in Sheet 2. Then I created a loop that if the Match value > 0, to then take the whole row of that "i" value and paste into sheet 3. For some reason my loop isn't looking at all the M & "i" cells because I have two cells that have a value greater than 0. I'd appreciate you're help, especially because I feel like I'm right there. Thanks again!
Code:
Sub SortData()
Sheets("Sheet1").Select
'Find last row in a dataset
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).row
Range("M2").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(MATCH(RC[-2], 'Sheet2'!R2C8:R1048576C8, 0), """")"
Range("M2").AutoFill Destination:=Range("M2:M" & Lastrow)
Columns("M:M").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
For i = 2 To Lastrow
If Sheets("Sheet1").Range("M" & i).Value > 0 Then
Else
Sheets("Sheet1").Select
Rows(i).Copy
Sheets("Sheet3").Select
Dim Lastrow2 As Long
Lastrow2 = Cells(Rows.Count, "A").End(xlUp).row
Dim Lastrow3 As Long
Lastrow3 = Lastrow2 + 1
Rows(Lastrow3).Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End If
Next i
End Sub