Layout in columns is:
Name, Date, In, Out
1)find name, if not input name, date and in time. (first button push) Punched in
2)check that punch out is empty, if yes, punch out. (second button push).
3)if user presses button again (3) code sees this and says already punched in.
Current code I can get one "run" completed correctly, but any after this no.
See code line red. This is because the name now will not = cell ever.
I need different logic but what? Any thoughts?
Name, Date, In, Out
1)find name, if not input name, date and in time. (first button push) Punched in
2)check that punch out is empty, if yes, punch out. (second button push).
3)if user presses button again (3) code sees this and says already punched in.
Current code I can get one "run" completed correctly, but any after this no.
See code line red. This is because the name now will not = cell ever.
I need different logic but what? Any thoughts?
Code:
[Private Sub CbDana_Click()
Dim name As String
name = "Dana"
Dim frmcontrol As MSForms.Control
' frmcontrol = "CbDana"
Call PlaceTime(name, CbDana)
End Sub
Code:
Public Sub PlaceTime(name As String, frmcontrol As MSForms.Control)
Dim worksht As String
Dim addme As Range
Dim LastRow As Long
'Dim selectedName As String
Dim cell As Range
Dim Myierror As Integer
Dim rng As Range
Myierror = 0
worksht = Worksheets("Newidea").Range("S16")
With ActiveSheet
LastRow = Cells(.Rows.count, "AH").End(xlUp).row + 1
End With
Myierror = 0
Call NameSearch(name, Myierror)
If Myierror = 1 Then Exit Sub
Set addme = Sheets(worksht).Cells(LastRow, 34)
addme = addme.Offset(0, 0)
addme.value = name
Set addme = addme.Offset(0, 1)
addme.value = Date
Set addme = addme.Offset(0, 1)
addme.value = Time()
If Time() > TimeValue("12:50:00PM") Then
frmcontrol.BackColor = vbRed
frmcontrol.Caption = "LATE"
Application.Wait (Now + TimeValue("00:00:03"))
frmcontrol.Caption = name
frmcontrol.BackColor = vbWhite
Else
frmcontrol.BackColor = vbGreen
frmcontrol.Caption = "Ok"
Application.Wait (Now + TimeValue("00:00:03"))
frmcontrol.Caption = name
frmcontrol.BackColor = vbWhite
End If
'hideAllSheets
End Sub
Code:
Private Sub NameSearch(name As String, Myierror As Integer)
'Call findrowname(name, Myierror)
Dim rng As Range
Dim cell As Range
Dim LastRow As Long
'FindNamev2 (name)
' Call findrowname(name, Myierror)
'
With ActiveSheet
LastRow = Cells(.Rows.count, "AH").End(xlUp).row + 1
End With
Set rng = ActiveSheet.Range("AH3:AH8")
For Each cell In rng
'Below line allows first preson in to punch in
If cell = "" Then Exit Sub
' If IsEmpty(cell) Then Exit Sub
If cell = name _
And IsEmpty(cell.Offset(0, 3)) = False Then
MsgBox "Sorry, you already punched in"
Myierror = 1
Exit Sub
' End
Else
cell.Offset(0, 3) = Time()
Myierror = 1
Exit Sub
' End
' MsgBox "no"
End If
' If cell <> name Then Exit Sub
Next cell
'
End Sub