I am trying to copy a value and paste it to another sheet based on criteria of a cell value by iterating a range.
Criteria: if a cell value of a row of the range has "new", copy a value of a different cell of the same row.
For example, look for 'new' in NewProd column, and if found, copy the values of Product AND Desc columns(the values of the two columns) of the same row.
The table looks like this: Table1
Problem: when pasting the copied value, the first iteration gets the correct value(the yellow row value), however the second iteration gets the same value as the first one. It should be the green row value in the image, but gets the yellow row value.
My code:
Sub AddNewProd()
Dim tbl As ListObject
Dim lr As Long
Dim lr2 As Long
Dim c As Range
Dim rng As Range
Dim prd As Range
Dim desc As Range
Set tbl = Sheets("sheet1").ListObjects("Table1")
'Count the number of the row of the NewProd column.
lr = tbl.Range.Rows.Count
lr2 = Sheets("sheet2").Cells.SpecialCells(xlCellTypeLastCell).Row
Sheets("sheet1").Select
Set rng = Sheets("sheet1").Range("AS2:AS" & lr)
Set prd = tbl.ListColumns("Product").DataBodyRange
Set desc = tbl.ListColumns("Desc").DataBodyRange
For Each c In rng
If c = "New" Then
prd.Offset(1).Resize(1, 2).SpecialCells(xlCellTypeVisible).Copy
Sheets("sheet2").Select
Range("A" & lr2 + 1).Select
ActiveSheet.Paste
lr2 = Sheets("sheet2").Cells.SpecialCells(xlCellTypeLastCell).Row
Application.CutCopyMode = False
End If
Next c
End Sub
