我有一个电子表格,要求我们的组织每周为员工提交疾病信息。电子表格一年中的每一周都有一个选项卡,我已经有一个宏可以将员工详细信息从一周复制到下一周。
我正在尝试在下面的代码中构建,它会挑选仍在休病假的员工,并将病假的开始日期复制到下一周。该代码通过在循环中选取一个员工编号作为字符串来工作,然后为开始日期创建一个对象。
由于模板上的布局和其他信息,我不能简单地从一周到下一周复制和粘贴整张工作表。
已修订
下面的修订代码现在将第一个SicknessStart
日期复制到NextWeek
. 但是,它仅适用于第一个日期,并且由于某种原因不会从后续行中复制信息。日期格式也在以美国格式复制,但我正在调查。
Sub CopyDate
Dim I As Integer, CopyDate As Boolean
I = 6
CopyDate = False
'Use the Employee Number column (C) to perform the check on the sickness dates
Do While CurrentWeek.Cells(I, 3) <> ""
'Check if there is a sickness start date in column R
If CurrentWeek.Cells(I, 18) <> "" Then
'Check if they have entered 'Still Away' or left the cell blank in column S
If CurrentWeek.Cells(I, 19) = "Still Away" Or CurrentWeek.Cells(I, 19) = "" Then
Dim EmployeeNumber As String
Dim SicknessStart As String
EmployeeNumber = Cells(I, 3)
SicknessStart = Cells(I, 18)
NextWeek.Select
'Find the employee number string on the following week's tab and enter sickness start date
Columns(3).Find(What:=EmployeeNumber, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Offset(0, 15) = SicknessStart
End If
End If
I = I + 1
Loop
CopySickness = True
End Sub