I am trying to compile a macro that compares each cell in Range D9:D60 to Range S9:S14. In case
a match is found, the macro should insert a row below the matched cell and copy a part of the
row (from column S to column W) in the inserted row at Column D. For example, if cells D10 and
S12 is a match and Y12 value is "Passed", a row should be inserted at D11 and range S12:W12
needs to be copied at D11. There may be multiple matches in column D, but this action needs to be
taken only on the first match.
I have the following code which doesn't give out an error but doesn't seem to work either.I
presume I may be quite close but unable to figure out the mistake I am making.
Any help will be much appreciated.
Code:
a match is found, the macro should insert a row below the matched cell and copy a part of the
row (from column S to column W) in the inserted row at Column D. For example, if cells D10 and
S12 is a match and Y12 value is "Passed", a row should be inserted at D11 and range S12:W12
needs to be copied at D11. There may be multiple matches in column D, but this action needs to be
taken only on the first match.
I have the following code which doesn't give out an error but doesn't seem to work either.I
presume I may be quite close but unable to figure out the mistake I am making.
Any help will be much appreciated.
Code:
VBA Code:
Dim c As Range
Dim e As Range
For Each c In Range("D9:D59")
For Each e In Range("S9:S14")
If c.Value = e.Value And Range("Y" & e.Row).Value = "Passed" Then
Range("C" & c.Row).Offset(1,0).EntireRow.Insert Shift:=x1Down
Range("S" & e.Row & ":W" & e.Row).Copy Worksheets("Stock").Range("D" & c.Row).Offset(1, 0)
Exit For
End If
Next e
Next c
End Sub