Sub test_2()
Randomize
xxx = cod(97)
MsgBox xxx
yyy = cod(, 12)
MsgBox yyy
End Sub
Private Function cod(Optional Casse = 65, Optional Nb_Car = 5) As String
[IV1600].Formula2 = "=TEXTJOIN("""",1,INDEX(CHAR(VSTACK(SEQUENCE(26,1," & Casse & ",1),SEQUENCE(10,1,48,1))),RANDARRAY(" & Nb_Car & ",1,1,36,-1)))"
cod = Range("IV1600").Value
End Function