this will set it at design time, requires access to vba projects to be enabled.
thisworkbook.VBProject.VBComponents("Userform1").Designer.controls("TextBox1").PasswordChar="*"
What I think you really mean is this, add code for Pwd4 only
Private Sub Worksheet_Change(ByVal Target As Range)
Dim pwd As String, PwdChk As String
Dim frmPwd As UserForm1
If Target.Cells.Count > 1 Then
MsgBox "Only one cell at a time may be edited"
GoTo UndoIT
Exit Sub
End If
If Target.Column >= 4 And Target.Column <= 7 Then
Select Case Target.Column
Case 4
PwdChk = P4 'column D
If Len(Pwd4) = 0 Then
Set frmPwd = New UserForm1
Load frmPwd
frmPwd.TextBox1.PasswordChar = "*"
frmPwd.Show
Pwd4 = frmPwd.TextBox1.Text
Unload frmPwd
Set frmPwd = Nothing
End If
If Pwd4 <> P4 Then
MsgBox "Password incorrect"
Pwd4 = ""
GoTo UndoIT
End If
Case 5
PwdChk = P5 'column E
If Len(Pwd5) = 0 Then Pwd5 = Application.InputBox("Enter password for this column...", "Password", Type:=2)
If Pwd5 <> P5 Then
MsgBox "Password incorrect"
Pwd5 = ""
GoTo UndoIT
End If
Case 6
PwdChk = P6 'column F
If Len(Pwd6) = 0 Then Pwd6 = Application.InputBox("Enter password for this column...", "Password", Type:=2)
If Pwd6 <> P6 Then
MsgBox "Password incorrect"
Pwd6 = ""
GoTo UndoIT
End If
Case 7
PwdChk = P7 'column G
If Len(Pwd7) = 0 Then Pwd7 = Application.InputBox("Enter password for this column...", "Password", Type:=2)
If Pwd7 <> P7 Then
MsgBox "Password incorrect"
Pwd7 = ""
GoTo UndoIT
End If
End Select
End If
Exit Sub
UndoIT:
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End Sub
Bookmarks