Results 1 to 6 of 6

Trouble with getting a checkbox to place a cell value when matching the textbox.

Threaded View

  1. #1
    Forum Contributor
    Join Date
    08-10-2014
    Location
    Alberta
    MS-Off Ver
    2016
    Posts
    128

    Trouble with getting a checkbox to place a cell value when matching the textbox.

    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.
    Attached Files Attached Files
    Last edited by Templemind; 09-15-2014 at 11:43 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] checkbox trouble
    By iwannabakat in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-10-2014, 09:56 PM
  2. [SOLVED] populate cell with textbox value when checkbox is true on another worksheet
    By Templemind in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-06-2014, 02:25 PM
  3. Userform to search textbox value to place other textbox values in worksheet
    By mattyh555 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-19-2012, 11:38 AM
  4. [SOLVED] Cannot place a picture again in another textbox
    By Yogi28 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-30-2012, 10:44 PM
  5. Matching, sorting and place in appr. cell
    By nachi in forum Excel General
    Replies: 2
    Last Post: 07-28-2011, 09:26 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1