View Full Version : [SOLVED:] Every time you open the UseForm, it generates a new code
jrsilverio
10-08-2022, 10:30 AM
I need help writing a code for TextBox, in which every time the UseForm is opened it automatically generates a random 6-digit code, letters and numbers in the TextBox6 field.
VBA Excel
Logit
10-08-2022, 02:12 PM
Option Explicit
Private Sub UserForm_Initialize()
Dim pw As String
Dim i As Integer
Randomize
For i = 1 To 6
If Int((2 * Rnd) + 1) = 1 Then
pw = pw & Chr(Int(26 * Rnd + 65))
Else
pw = pw & Int(10 * Rnd)
End If
Next i
TextBox1.Text = pw
End Sub
jrsilverio
10-09-2022, 04:45 AM
thank you so much my king
Logit
10-09-2022, 09:59 AM
You are welcome.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.