Results 1 to 5 of 5

Match data in cells then enter date in empty cell

Threaded View

  1. #1
    Registered User
    Join Date
    11-07-2011
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2016
    Posts
    18

    Match data in cells then enter date in empty cell

    Ive been working on a project and finally got it somewhat working. This the timeclock fuction of the entire workbook that im needing a second head to figure out. The code i have uploaded is what i have so far which works, sort of.

    Private Sub cmdClockOut_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("WeeklySummary")
    
    'find first empty row in database
    iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
        SearchDirection:=xlPrevious, LookIn:=xlValues).Row
    
    'check for a part number
    If Trim(Me.ComboBox1.Value) = "" Then
      Me.ComboBox1.SetFocus
      MsgBox "Please choose your last name from the dropdown"
      Exit Sub
    End If
    
    'copy the data to the database
    ws.Cells(iRow, 6).Value = Me.ComboBox2.Value
    ws.Cells(iRow, 7).Value = Me.txtNotes.Value
    'ws.Cells(iRow, 2).Value = Me.txtFName.Value
    'ws.Cells(iRow, 3).Value = Me.Label1.Value
    
    'clear the data
    Me.ComboBox1.Value = ""
    Me.txtFName.Value = ""
    Me.autoaddress.Value = ""
    Me.autoCity.Value = ""
    Me.autoState.Value = ""
    Me.autoZip.Value = ""
    Me.ComboBox2.Value = ""
    Me.txtNotes.Value = ""
    Me.ComboBox1.SetFocus
    
    End Sub
    This code is attached to the clockout command button and works the way it is suppose to with one exception. I need to search for the correct record before this code fires. What i mean by that is this:
    I need to search in column A to match value (the Last Name) which is contained in me.ComboBox1, I also need to check that column F of that row which contains the matched record is empty. if both matches are true, then it inserts a job code that fires the second code set. The value of the me.combobox1 could show up multiple times but only one should have an empty cell in the F column. Once the second code set fires, (inserts the job code) the current time is then inserted into the cell directly to the left of the job code. (offset(,-1)) The second code set:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim cell As Range
            If Not Intersect(Target, Range("a1:a65536")) Is Nothing Then
                For Each cell In Target
                        cell.Offset(0, 3) = Format(Now(), "hh:mm")
                        cell.Offset(0, 2) = Format(Now(), "mm/dd/yy")
                Next cell
        End If
             If Not Intersect(Target, Range("F1:F65536")) Is Nothing Then
                For Each cell In Target
                        cell.Offset(0, -1) = Format(Now(), "hh:mm")
                Next cell
        End If
    End Sub
    You'll notice that this code set is also used when the user is clocking in. That part works fine.

    Last but not least, Ive uploaded a copy of this part of the workbook for testing. Open the workbook and click either of the buttons, the questionable code is under the ClockIn/Out button.

    Thanks in advance guys and gals for all your help.

    ** sorry, i havent had a chance to format the first code set to make it eaiser to read**
    Attached Files Attached Files
    Last edited by MyComputerGuy; 08-08-2012 at 11:42 PM. Reason: additional info

Thread Information

Users Browsing this Thread

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

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