Trevor3007
Well-known Member
- Joined
- Jan 26, 2017
- Messages
- 675
- Office Version
- 365
- Platform
- Windows
good evening,
I use this code:-
Sub Gencode()
ActiveSheet.Unprotect
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("b3:b199")
PW = vbNullString
For i = 1 To 8
Do
DoEvents
PW1 = Chr(Int((97 - 122 + 1) * Rnd + 122)) ' Lower case alpha
Loop Until InStr(1, PW, PW1, 1) = 0
PW = PW & PW1
Next i
PW = Replace(PW, Mid(PW, Int(8 * Rnd + 1), 1), Int(8 * Rnd + 1))
cell.Value = PW
Next cell
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True
End Sub
it runs fine if I just run it from the applicable worksheet. My issue is I want to run this from another worksheet within the workbook . If I try to run from another worksheet it puts the code into the wrong worksheet column.
Is anyone able to solve this for me
KR
Trevor3007
I use this code:-
Sub Gencode()
ActiveSheet.Unprotect
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("b3:b199")
PW = vbNullString
For i = 1 To 8
Do
DoEvents
PW1 = Chr(Int((97 - 122 + 1) * Rnd + 122)) ' Lower case alpha
Loop Until InStr(1, PW, PW1, 1) = 0
PW = PW & PW1
Next i
PW = Replace(PW, Mid(PW, Int(8 * Rnd + 1), 1), Int(8 * Rnd + 1))
cell.Value = PW
Next cell
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True
End Sub
it runs fine if I just run it from the applicable worksheet. My issue is I want to run this from another worksheet within the workbook . If I try to run from another worksheet it puts the code into the wrong worksheet column.
Is anyone able to solve this for me
KR
Trevor3007