我已经创建了一个基本的时间卡,可以在每天为多个用户在Excel上运行。我遇到了两个我正在寻求帮助的问题。
Sub ClockInClockOut()
'This code looks for empty cells in the range H1:H21
'and allows the user to clock-in and clock-out.
'It looks at cells one by one and enters time stamp.
Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
Dim currentRowValue As String
sourceCol = 8 'column H has a value of 8
rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row
'for every row, find the first blank cell and select it
For currentRow = 1 To rowCount
currentRowValue = Cells(currentRow, sourceCol).Value
If IsEmpty(currentRowValue) Or currentRowValue = "" Then
Cells(currentRow, sourceCol).Select
Exit For
End If
Next
ActiveCell.FormulaR1C1 = "=NOW()"
Selection.NumberFormat = "[$-en-US]mm/dd/yyyy hh:mm AM/PM;@"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
答案 0 :(得分:0)
如果您专门查看范围H1:H21,则代码可能正常工作
Sub ClockInClockOut2()
Dim c As Range
For Each c In Range("myTimestamps")
If IsEmpty(c) Or c.Value = "" Then
With c
.Value = Now()
.NumberFormat = "[$-en-US]mm/dd/yyyy hh:mm AM/PM;@"
Exit For
End With
End If
Next c
End Sub