I'm trying to use VBA to create a macro that searches the "Analysis" sheet, column P, for "#N/A" text values. In the event that "N/A" text values are found in Column P, it pulls the corresponding cell data from that row's Column A and then instead of just pasting this info in the first available row at the bottom of Column A of the "Template" sheet, I need to insert a row for the info because it's being pasted into a table that has sums at the bottom. I'm new to VBA, any help would be appreciated! Also the data in column P may not start in P1, it maybe P5 or P7 or something depending on user formatting, ideally that doesn't matter.
Sub ADDNA()
Sheets("Analysis").Select
Table1 = Worksheets("Analysis").Range("P:P")
Table2 = Worksheets("Analysis").Range("A:P")
For Each cl In Table1
If cl.Value = "#N/A" Then
Worksheets("Template").Select
Worksheets("Template").Range("A3").End(xlDown).Select
Set Target = ActiveCell
Target.Offset(1).EntireRow.Insert shift:=xlUp
Worksheets("Template").Range("A3").End(xlDown) = Application.WorksheetFunction.VLookup(cl, Table2, 16, 0)
End If
Next cl
End Sub