Hello guys,
Please I am lost. I have searched the forum to see if I can find a previous thread but could not.
My problem: Iam trying to develope a time sheet to enable us clock in/out from a computer. I have a user form that holds a combo box and the combobox is populated with my staff names. What I want is when a staff selects his name from the combobox, it shoud activate a worksheet with the staff's name. this worksheet becomes the active worksheet to capture the staff time inputs. I have bellow the codes I am using.
Please help.
Private Sub CmbName_Change()
Dim ws As Worksheet
Select Case CmbName.Value
Case "kelly"
Set ws = Worksheets("kelly")
End Select
End Sub
Private Sub CmdAdd_Click()
Dim lRow As Long
Dim intTimein As Integer
Dim intTimeout As Integer
Dim lTot As Long
Dim ws As Worksheet
Set ws = ActiveSheet
'check for empty combobox
If Trim(Me.CmbName.Value) = "" Then
Me.CmbName.SetFocus
MsgBox "Please enter Name"
Exit Sub
End If
'find first empty row in database
lRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'lName = Me.CmbName.ListIndex
'copy the data to active worksheet
With ws
.Cells(lRow, 1).Value = Me.CmbName.Value
.Cells(lRow, 2).Value = Me.TxtdATE.Value
.Cells(lRow, 3).Value = Me.TxtTimeIN.Value
.Cells(lRow, 4).Value = Me.TxtTimeOut.Value
.Cells(lRow, 5).Value = Me.TxtLunchOut.Value
.Cells(lRow, 6).Value = Me.TxtLunchIN.Value
.Cells(lRow, 7).Value = FormatDateTime(TimeValue("00:00:01AM") + TimeValue("23:59:59PM") + TimeValue(Me.TxtTimeOut.Value) - TimeValue(Me.TxtTimeIN.Value), vbShortTime)
End If
End With
'clear the data
Me.CmbName.Value = ""
Me.TxtdATE.Value = ""
Me.TxtTimeIN.Value = Format(Time, "h:m")
Me.TxtTimeOut.Value = Format(Time, "h:m")
Me.TxtLunchIN.Value = Format(Time, "h:m")
Me.TxtLunchOut.Value = Format(Time, "h:m")
Me.CmbName.SetFocus
End Sub
Private Sub Cmdclose_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim cName As Range
Dim cDays As Range
Dim ws As Worksheet
Set ws = Worksheets("lookupList")
'populate name combo box
For Each cName In ws.Range("Namelist")
With Me.CmbName
.AddItem cName.Value
.List(.ListCount - 1, 1) = cName.Offset(0, 1).Value
End With
Next cName
Me.TxtTimeIN.Value = Format(Time, "h:m")
Me.TxtTimeOut.Value = Format(Time, "h:m")
Me.TxtLunchIN.Value = Format(Time, "h:m")
Me.TxtLunchOut.Value = Format(Time, "h:m")
Me.CmbName.SetFocus
End Sub
Bookmarks