I have the following VBA code, but one line is giving an error:
rng(i, 4).Formula = "=IF(LEFT(A" & (i + 1) & ",2)="RN","RN",IF(LEFT(A" & (i + 1) & ",2)="EX","EX",""))"
Can someone help me correct this?
Sub ITEM()
Dim dat As Variant
Dim rng As Range
Dim i As Long
Set rng = Range("F5:F50000")
dat = rng
For i = LBound(dat, 1) To UBound(dat, 1)
If dat(i, 1) <> "" Then
rng(i, 2).Formula = "=(F" & (i + 1)
rng(i, 3).Formula = "=vlookup(J" & (i + 1) & ",A:B,2,0)"
rng(i, 4).Formula = "=IF(LEFT(A" & (i + 1) & ",2)="RN","RN",IF(LEFT(A" & (i + 1) & ",2)="EX","EX",""))"
End If
Next
End Sub
rng(i, 4).Formula = "=IF(LEFT(A" & (i + 1) & ",2)=""RN"",""RN"",IF(LEFT(A" & (i + 1) & ",2)=""EX"",""EX"",""""))"LEFT()(assuming newish Excel version)"=LET(lft,LEFT(A" & (i + 1) & ",2),switch(lft,""RN"",lft,""EX"",lft,""""))"