我的工作人员有一张时间表,他使用下面的订单记录他们的时间
Categories Washing Cleaning Office Duties Baking Cooking
Date Hours Hours Hours Hours Hours Hours
Jan/1/13 3.00 6.00
Jan/2/13
Jan/6/13 3.00
Jan/10/13
基本上我想要的是有一个代码,根据相关类别将日期和小时数复制到另一个名为Report的工作表。我需要三列作为输出日期小时类别。
答案 0 :(得分:1)
尝试以下代码:
Sub sample()
Dim lastRow As Long
Dim col As Long
Dim a As String, b As String, c As String
With Sheets("sheet1")
lastRow = .Range("A" & Rows.Count).End(xlUp).Row
If lastRow < 4 Then lastRow = 4
For i = 4 To lastRow
For col = 2 To 7
If .Cells(i, col) <> "" Then
a = .Cells(i, 1)
b = .Cells(i, col)
c = .Cells(1, col)
With Sheets("Report")
.Range("A" & .Range("A" & .Rows.Count).End(xlUp).Row + 1).Value = a
.Range("B" & .Range("B" & .Rows.Count).End(xlUp).Row + 1).Value = b
.Range("C" & .Range("C" & .Rows.Count).End(xlUp).Row + 1).Value = c
End With
End If
Next
Next
End With
End Sub
答案 1 :(得分:0)
你有没有试过像:
Sheet2.Range("A1").Value = Sheet1.Range("A1").Value
或
Sheet2.Range("A1").Text = Sheet1.Range("A1").Text
也许你可以做一个循环并做类似的事情:
Sheet2.Range("A" & i).Value = Sheet1.Range("A" & i).Value
有很多选项可以做到这一点......甚至是Range.Copy(参见:http://msdn.microsoft.com/en-us/library/office/ff837760.aspx)
祝你好运。