Sub autofill()
Set s = Selection
Set sh = Sheets("Dat").UsedRange
a = Array("LUC", "RST", "BHK", "LNC")
ReDim m(1 To 1, 1 To 9)
For i = 0 To UBound(a)
If UCase(s(1)) Like a(i) & "*" Then
For j = s.Row To 1 Step -1
If Cells(j, 1) = Cells(j, 7) And Cells(j, 1) <> "" _
Then m(1, 2) = Cells(j, 1): m(1, 3) = Cells(j, 2): Exit For
Next
m(1, 1) = Application.CountIf(sh, m(1, 2)) + 1
m(1, 4) = s(3)
m(1, 5) = s(4)
m(1, 6) = s(2)
m(1, 7) = a(i)
m(1, 8) = Split(Split(s(7), ",")(0), " ")(UBound(Split(Split(s(7), ",")(0), " ")))
m(1, 9) = s(5)
sh.Offset(sh.Rows.Count).Resize(1, 9).Value = m
Exit For
End If
Next
End Sub