Hi guys could you please correct my code because it is only working in preventing a duplicate time-in entry in my Sheet1 worksheet.
My objective is user Peter Pan should have a daily time-in entry in the worksheet using my excel VB userform
Problem - once the code check for existing entry, it can no longer add a new time-in entry for user Peter Pan.
Dim lRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
Application.ScreenUpdating = False
With Sheets("Sheet1")
If WorksheetFunction.CountIf(.Columns(3), ComboBox1) > 0 Then
MsgBox " You are Already Timed-in", vbCritical, "Employee Time-in"
Else
' Find emtpy row
lRow = ws.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
'Add data to worksheet
sh.Range("A" & last_Row + 1).Value = "=Row()-1"
sh.Range("B" & last_Row + 1).Value = Me.TextBox1.Value
sh.Range("C" & last_Row + 1).Value = Me.ComboBox1.Value
sh.Range("D" & last_Row + 1).Value = Me.ComboBox2.Value
sh.Range("E" & last_Row + 1).Value = Date
sh.Range("F" & last_Row + 1).Value = Time
MsgBox "SUCCESSFULLY LOGGED IN", Title:="VISUAL TIMESHEET"
End If
End With
'-----------------------Clear data after saving
Me.ComboBox1.Value = ""
Me.ComboBox2.Value = ""
Me.TextBox1.Value = ""
Call Refresh_Data
End Sub
My objective is user Peter Pan should have a daily time-in entry in the worksheet using my excel VB userform
Problem - once the code check for existing entry, it can no longer add a new time-in entry for user Peter Pan.
Dim lRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
Application.ScreenUpdating = False
With Sheets("Sheet1")
If WorksheetFunction.CountIf(.Columns(3), ComboBox1) > 0 Then
MsgBox " You are Already Timed-in", vbCritical, "Employee Time-in"
Else
' Find emtpy row
lRow = ws.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
'Add data to worksheet
sh.Range("A" & last_Row + 1).Value = "=Row()-1"
sh.Range("B" & last_Row + 1).Value = Me.TextBox1.Value
sh.Range("C" & last_Row + 1).Value = Me.ComboBox1.Value
sh.Range("D" & last_Row + 1).Value = Me.ComboBox2.Value
sh.Range("E" & last_Row + 1).Value = Date
sh.Range("F" & last_Row + 1).Value = Time
MsgBox "SUCCESSFULLY LOGGED IN", Title:="VISUAL TIMESHEET"
End If
End With
'-----------------------Clear data after saving
Me.ComboBox1.Value = ""
Me.ComboBox2.Value = ""
Me.TextBox1.Value = ""
Call Refresh_Data
End Sub