[英]copy multiple columns from one sheet to another
我有一个时间表,供我的工人使用下面的顺序记录他们的时间
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
基本上,我想要的是一个代码,该代码将根据相关类别的带有小时数的日期复制到另一个称为“报表”的工作表中。 我需要三列作为输出日期小时类别。
试试下面的代码:
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
您是否尝试过类似的方法:
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/zh-cn/library/office/ff837760.aspx )
祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.