VBA Code:

```
Sub LookupPrime()
Dim r As Range
Dim s As Range
Dim lastA As Long
Application.ScreenUpdating = False
ThisWorkbook.Worksheets("InvList").Select
lastA = Range("A" & Rows.Count).End(xlUp).Row
Range("R1").Value = "lookup"
Range("S1").Value = "Wafer Type"
Set r = Range("R2" & ":R" & lastA)
r.Formula = "=VLOOKUP(Q2,PRef!A:B,2,0)"
r.Value = r.Value
Set s = Range("S2" & ":S" & lastA)
s.Formula = "=IF(ISERROR(R2),P2,R2)"
s.Value = s.Value
Application.ScreenUpdating = True
End Sub
```