So I have a userform the has two textboxes and two checkboxes. The first textbox is the Guestname and the second is Roomnum. The two checkboxes are called MSbox and ONbox. When a user inputs the same username that is already there, the room number gets put into a separate column (up to 3 times).
What I am having trouble with is when the MSbox is true, then it puts a M/S in column F with the corresponding name if it already there.
Here is the current code for the MSbox:
If MSbox.Value = True Then
Res = Application.Match(Guestname.Value, .Columns(2), 0)
If Not IsError(Res) Then
emptyCol = Application.CountA(.Rows(Res).Range("F6:F38")) = "M/S"
emptyRow = Res
Else
emptyRow = .Range("F" & Rows.Count).End(xlUp).Row + 1 = "M/S"
End If
End If
Here is the other code I have for the textboxes (there is more code, but I left some out to simplify it, here is what I have):
Private Sub SubmitButton_Click()
Dim emptyRow As Long
Dim emptyCol As Long
Dim Res As Variant
Dim ctl As Control
If ONbox.Value = True Then
Res = Application.Match(Guestname.Value, .Columns(15), 0)
If Not IsError(Res) Then
MsgBox "Individual has had an overnight more than three times in a five month period. He/She is allowed back on: " & Range("P4"), vbOKOnly + vbCritical, "Overnight Ban"
Guestname.Value = ""
Roomnum.Value = ""
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then ctl.Value = False
Next ctl
Exit Sub
End If
Else
End If
If MSbox.Value = True Then
Res = Application.Match(Guestname.Value, .Columns(2), 0)
If Not IsError(Res) Then
emptyCol = Application.CountA(.Rows(Res).Range("F6:F38")) = "M/S"
emptyRow = Res
Else
emptyRow = .Range("F" & Rows.Count).End(xlUp).Row + 1 = "M/S"
End If
End If
Res = Application.Match(Guestname.Value, .Columns(2), 0)
If Not IsError(Res) Then
emptyCol = Application.CountA(.Rows(Res).Range("C1:E1")) + 3
emptyRow = Res
If emptyCol > 5 Then
MsgBox "All 3 visits have been used"
Guestname.Value = ""
Roomnum.Value = ""
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then ctl.Value = False
Next ctl
Exit Sub
End If
Else
emptyRow = .Range("B" & Rows.Count).End(xlUp).Row + 1
End If
Cells(emptyRow, 2).Value = Guestname.Value
Cells(emptyRow, emptyCol).Value = Roomnum.Value
End With
Unload Name_usrfrm
End Sub
I will also attach my workbook if you want to check it out.
Bookmarks