Trevor3007
Well-known Member
- Joined
- Jan 26, 2017
- Messages
- 675
- Office Version
- 365
- Platform
- Windows
Hi,
I have this code that creates a random a password into a range:-
Sub autocode()
Static IsRandomized As Boolean
Dim i As Integer, PW1 As String
Dim cell As Range, PW As String
If Not IsRandomized Then Randomize: IsRandomized = True
For Each cell In Range("A2:A3007")
PW = vbNullString
For i = 1 To 9
Do
DoEvents
PW1 = Chr(Int((96 - 123 + 1) * Rnd + 123)) ' Lower case alpha
Loop Until InStr(1, PW, PW1, 1) = 0
PW = PW & PW1
Next i
PW = Replace(PW, Mid(PW, Int(9 * Rnd + 1), 1), Int(9 * Rnd + 1))
cell.Value = PW
Next cell
End Sub
I need to add this into the above (either before of after):-
Dim myValue As Variant
myValue = InputBox("Give me some input")
Range("b2").Value = myValue
The random code works OK, but the 'red' code above does not ( I have tried this on its own & its Ok)
Oh.... I also need YES/NO msgbox before the 'red code' is ran to ask if they want to enter txt into cell b2 or not?
Could you solve my issue please?
Thank you for your help .
KR
Trevor3007
I have this code that creates a random a password into a range:-
Sub autocode()
Static IsRandomized As Boolean
Dim i As Integer, PW1 As String
Dim cell As Range, PW As String
If Not IsRandomized Then Randomize: IsRandomized = True
For Each cell In Range("A2:A3007")
PW = vbNullString
For i = 1 To 9
Do
DoEvents
PW1 = Chr(Int((96 - 123 + 1) * Rnd + 123)) ' Lower case alpha
Loop Until InStr(1, PW, PW1, 1) = 0
PW = PW & PW1
Next i
PW = Replace(PW, Mid(PW, Int(9 * Rnd + 1), 1), Int(9 * Rnd + 1))
cell.Value = PW
Next cell
End Sub
I need to add this into the above (either before of after):-
Dim myValue As Variant
myValue = InputBox("Give me some input")
Range("b2").Value = myValue
The random code works OK, but the 'red' code above does not ( I have tried this on its own & its Ok)
Oh.... I also need YES/NO msgbox before the 'red code' is ran to ask if they want to enter txt into cell b2 or not?
Could you solve my issue please?
Thank you for your help .
KR
Trevor3007