|
用公式比较困难,用宏就比较简单了——
- Option Explicit
- Sub GetInfo()
- Dim c As Range, arr(9999, 4), i%, j%
- With Sheet1
- arr(0, 0) = "日期"
- arr(0, 1) = "星期"
- arr(0, 2) = "姓名"
- arr(0, 3) = "上班"
- arr(0, 4) = "下班"
- For Each c In .Range("A3:A" & .[A65536].End(xlUp).Row + 1)
- If Len(c.Value) > 0 Then
- For i = 1 To 31
- arr(i + 31 * j, 0) = .Cells(1, i + 2).Value
- arr(i + 31 * j, 1) = .Cells(2, i + 2).Value
- If i = 1 Then arr(i + 31 * j, 2) = c.Value
- arr(i + 31 * j, 3) = c.Offset(0, i + 1).Value
- arr(i + 31 * j, 4) = IIf(c.Offset(2, 0).Value > 0, c.Offset(1, i + 1).Value, IIf(c.Offset(2, i + 1).Value > 0, c.Offset(2, i + 1).Value, c.Offset(1, i + 1).Value))
- Next i
- j = j + 1
- End If
- Next c
- End With
- With Sheet2.[G2]
- .CurrentRegion.Clear
- .Resize(10000, 5) = arr
- .CurrentRegion.Borders.LineStyle = xlContinuous
- .CurrentRegion.HorizontalAlignment = xlCenter
- .CurrentRegion.Rows(1).Font.Bold = True
- End With
- End Sub
复制代码
|
|