Maybe:
Sub codegenerator()
On Error GoTo Default
If IsNumeric(WorksheetFunction.Match(Range("D2"), Sheets("Sheet2").Range("A1:A10"), 0)) Then _
Range("D2") = Sheets("Sheet2").Range("A" & WorksheetFunction.Match(Range("D2"), Sheets("Sheet2").Range("A1:A10"), 0) + 1)
Else:
Default:
Range("D2") = Sheets("Sheet2").Range("A1")
End If
End Sub
I had my code generated in D2.
My list of code was on Sheet2, A1:A10. If D2 is blank, it plops Sheet2A1. If it already contains one from the list, it instead gives the next one on the list.
Bookmarks