GeorgeWhite
New Member
- Joined
- Apr 20, 2017
- Messages
- 27
Hello,
I currently have a userform which is shown after a selection on another userform. This userform requires you to type in a number which I have set a maximum length to 8 characters. I am now looking for a way to modify this to have a minimum of 8 characters too. I would like for it that when they select the ok button a message will pop up saying "Minimum of 8 characters only" and then the userform will be presented again and this will loop until they submit at least the minimum/maximum.
This is the current code I am using for the maximum characters:
But I also have this code for the command button:
Many thanks.
I currently have a userform which is shown after a selection on another userform. This userform requires you to type in a number which I have set a maximum length to 8 characters. I am now looking for a way to modify this to have a minimum of 8 characters too. I would like for it that when they select the ok button a message will pop up saying "Minimum of 8 characters only" and then the userform will be presented again and this will loop until they submit at least the minimum/maximum.
This is the current code I am using for the maximum characters:
Code:
Private Sub UserForm_Initialize()
HideTitleBar Me
Me.TextBox1.MaxLength = 8
End Sub
But I also have this code for the command button:
Code:
Private Sub CommandButton2_Click()
Dim Cert As String
Cert = Me.TextBox1.Value
For Each cell In Worksheets("Certificate#").Range("A2:A500")
If cell.Value = Cert Then
If MsgBox("Certificate number already in use.", vbInformation) = vbOK Then
Me.TextBox1.Text = ""
End If
Exit Sub
End If
Next cell
Dim lRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Certificate#")
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Cells(lRow, 1).Value = Me.TextBox1.Value
End With
Me.TextBox1.Value = ""
Unload CertificateNo
End Sub
Many thanks.