This is my first time trying to put together a UserForm and it is getting to be a little more complicated than I thought. Everytime I run this, the userform pops up and everything works fine until I hit the "Sign Up" button which causes a "Subscript out of range" error. It started after I added the section for writing the data to the spreadsheet. I don't know what I'm doing wrong. HELP!
Private Sub SignUpButton_Click()
Dim RowCount As Long
Dim ctl As Control
'Check user input
If Me.WWIDEntry.Value = "" Then
MsgBox "Please enter a WorldWide ID.", vbExclamation, "Incomplete Form"
Me.WWIDEntry.SetFocus
Exit Sub
End If
If Me.FirstNameEntry.Value = "" Then
MsgBox "Please enter a First Name.", vbExclamation, "Incomplete Form"
Me.FirstNameEntry.SetFocus
Exit Sub
End If
If Me.LastNameEntry.Value = "" Then
MsgBox "Please enter a Last Name.", vbExclamation, "Incomplete Form"
Me.LastNameEntry.SetFocus
Exit Sub
End If
If Me.DepartmentEntry.Value = "" Then
MsgBox "Please enter a Department.", vbExclamation, "Incomplete Form"
Me.DepartmentEntry.SetFocus
Exit Sub
End If
'Write data to worksheet
RowCount = Worksheets("Sign Up").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sign Up").Range("A1")
.Offset(RowCount, 1).Value = Me.WWIDEntry.Value
.Offset(RowCount, 2).Value = Me.LastNameEntry.Value
.Offset(RowCount, 3).Value = Me.FirstNameEntry.Value
.Offset(RowCount, 4).Value = Me.NicknameEntry.Value
.Offset(RowCount, 5).Value = Me.DepartmentEntry.Value
End With
' Clear the form
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
ElseIf TypeName(ctl) = "CheckBox" Then
ctl.Value = False
End If
Next ctl
End Sub
Bookmarks