ocular
New Member
- Joined
- Jan 22, 2025
- Messages
- 0
- Office Version
- Prefer Not To Say
- Platform
- Windows
Sub LogTimeSimple()
Dim ws As Worksheet
Dim currentTime As String
Dim lastRow As Long
Dim currentCell As Range
' Set the worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
' Get the current time and date
currentTime = Format(Time, "HH:mm:ss")
' Find the last row with a date in column A
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
' If the last row is empty or not today, start a new row
If ws.Cells(lastRow, 1).Value <> Format(Date, "MM/DD/YYYY") Then
lastRow = lastRow + 1
ws.Cells(lastRow, 1).Value = Format(Date, "MM/DD/YYYY")
End If
' Loop through columns B to E for the current row
For Each currentCell In ws.Range(ws.Cells(lastRow, 2), ws.Cells(lastRow, 5))
If currentCell.Value = "" Then
currentCell.Value = currentTime
Exit Sub
End If
Next currentCell
End Sub
Dim ws As Worksheet
Dim currentTime As String
Dim lastRow As Long
Dim currentCell As Range
' Set the worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
' Get the current time and date
currentTime = Format(Time, "HH:mm:ss")
' Find the last row with a date in column A
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
' If the last row is empty or not today, start a new row
If ws.Cells(lastRow, 1).Value <> Format(Date, "MM/DD/YYYY") Then
lastRow = lastRow + 1
ws.Cells(lastRow, 1).Value = Format(Date, "MM/DD/YYYY")
End If
' Loop through columns B to E for the current row
For Each currentCell In ws.Range(ws.Cells(lastRow, 2), ws.Cells(lastRow, 5))
If currentCell.Value = "" Then
currentCell.Value = currentTime
Exit Sub
End If
Next currentCell
End Sub