Userform - Find Matching Date in column then send data? If data exists, error message?

mnoah

Board Regular
Joined
Oct 14, 2015
Messages
54
Hello everyone,

I have a UserForm which allows staff to pick individual workers, choose a job, then enter a quantity. The script will find all matching names that were selected and then sends the quantity to the next open column in that row. The problem is if data is entered more than once a day, usually accidentally. In the example below, someone entered payroll data twice today (25 pieces for all, then 25 for only three workers).

If I include a Date Text Box in the form, is there a way to only send the data to the matching date of the column? So that if someone tried to enter data twice for one day, an error message would pop up, saying something like "Payroll data already exists for the date selected" but only for the workers chosen.


xB3lxMv.png


Code:
Private Sub submitButton_Click()


Dim Found As Range
Dim i As Long
Dim msg As String
Dim Check As String
    
   
    
        With multiSelectListBox
            For i = 0 To .ListCount - 1
                If .Selected(i) Then
                msg = msg & .List(i) & vbNewLine
                End If
                Next i
                End With
          
          If msg = vbNullString Then
         'If nothing was selected, tell user and let them try again
        MsgBox "Nothing was selected!  Please select an individual(s)!"
        Exit Sub
    Else
         'Ask the user if they are happy with their selection(s)
        Check = MsgBox("You selected:" & vbNewLine & msg & vbNewLine & "Hours/Pieces: " & TextBox3.Value & vbNewLine & vbNewLine & _
        "Are you happy with your selections?", _
        vbYesNo + vbInformation, "Please confirm")
    End If
     
    If Check = vbNo Then
         'clears data and starts over
       For i = 0 To multiSelectListBox.ListCount - 1
            multiSelectListBox.Selected(i) = False
       Next
    End If
          
    'Checks to make sure a job was selected
    If IsNull(ComboBox2) Then
            MsgBox "No Job Selected!"
    Exit Sub
    End If
    
    If TextBox3.Value = "" Then
    MsgBox "No Quantity Entered!"
    Exit Sub
    End If
    
    Worksheets(ComboBox2.Value).Activate
          
            
            With multiSelectListBox
            For i = 0 To .ListCount - 1
                If .Selected(i) Then
                'finds all matching names in worksheet that were selected in the userform
                Set Found = ActiveSheet.Range("A2:A37").Find(What:=Me.multiSelectListBox.List(i), _
                                                                                LookIn:=xlValues, _
                                                                                LookAt:=xlWhole, _
                                                                            SearchOrder:=xlByRows, _
                                                                            SearchDirection:=xlNext, _
                                                                                MatchCase:=False)
                
              
                ActiveSheet.Cells(Found.Row, Columns.Count).End(xlToLeft).Offset(, 1).Value = Me.TextBox3.Value
                'clears the listbox
                multiSelectListBox.Selected(i) = False
                
                Else
                End If
            Next i
            End With
            
    
    'Updates image if user updates payroll, then activates that page
    If ActiveSheet.Name = "THORLAB - BITES" Then
    Call UpdateTableBites
    MultiPage1.Value = 0
    ElseIf ActiveSheet.Name = "THORLAB - BOXES" Then
    Call UpdateTableBoxes
    MultiPage1.Value = 1
    ElseIf ActiveSheet.Name = "THORLAB - SNACKS" Then
    Call UpdateTableSnacks
    MultiPage1.Value = 2
    ElseIf ActiveSheet.Name = "GLOBAL" Then
    Call UpdateTableGlobal
    MultiPage1.Value = 3
    ElseIf ActiveSheet.Name = "GLOVES" Then
    Call UpdateTableGloves
    MultiPage1.Value = 4
    ElseIf ActiveSheet.Name = "CLEANING" Then
    Call UpdateTableCleaning
    MultiPage1.Value = 5
    ElseIf ActiveSheet.Name = "LAUNDRY" Then
    Call UpdateTableLaundry
    MultiPage1.Value = 6
    ElseIf ActiveSheet.Name = "SHREDDING" Then
    Call UpdateTableShredding
    MultiPage1.Value = 7
    
    End If
    MsgBox "Submitted!"
    ComboBox2.Value = ""
    TextBox3.Value = ""
    


    
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top