VBA工资条,帮我看看下面的代码哪儿有问题,怎么提示“运行时错误1004,方法RANGE 作用于WORKSHEET时失败
Subgonzitiao()DimiAsIntegerDimendrowAsInteger'测出数据的最后一行endrow=Sheet1.Range("a65536")....
Sub gonzitiao()
Dim i As Integer
Dim endrow As Integer
'测出数据的最后一行
endrow = Sheet1.Range("a65536").End(xlUp).Row - 1
'把标题贴过去
Worksheets(1).Range("1:1").Copy (Worksheets(2).Cells(1, 1))
For i = 3 To endrow
'把每条数据抬头贴过去
Worksheets(1).Range("2:2").Copy (Worksheets(2).Cells(3 * i - 7, 1))
'把数据贴过去
Sheet1.Range(Cells(i, 1), Cells(i, 256)).Copy (Sheet2.Cells(3 * i - 6, 1))
Next
End Sub 展开
Dim i As Integer
Dim endrow As Integer
'测出数据的最后一行
endrow = Sheet1.Range("a65536").End(xlUp).Row - 1
'把标题贴过去
Worksheets(1).Range("1:1").Copy (Worksheets(2).Cells(1, 1))
For i = 3 To endrow
'把每条数据抬头贴过去
Worksheets(1).Range("2:2").Copy (Worksheets(2).Cells(3 * i - 7, 1))
'把数据贴过去
Sheet1.Range(Cells(i, 1), Cells(i, 256)).Copy (Sheet2.Cells(3 * i - 6, 1))
Next
End Sub 展开
3个回答
展开全部
Sheet1.Range(Cells(i, 1), Cells(i, 256)).Copy (Sheet2.Cells(3 * i - 6, 1))
这句中
(Cells(i, 1), Cells(i, 256)) 没有指明父对象.
修改为
Sheet1.Range(sheet1.Cells(i, 1), sheet1.Cells(i, 256)).Copy (Sheet2.Cells(3 * i - 6, 1))
或者简化为:
with sheet1
.range(.cells(i,1),.cells(i,256)).copy sheet2.cells(3 * i - 6, 1)
end with
这句中
(Cells(i, 1), Cells(i, 256)) 没有指明父对象.
修改为
Sheet1.Range(sheet1.Cells(i, 1), sheet1.Cells(i, 256)).Copy (Sheet2.Cells(3 * i - 6, 1))
或者简化为:
with sheet1
.range(.cells(i,1),.cells(i,256)).copy sheet2.cells(3 * i - 6, 1)
end with
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用以下代码即可
Sub gonzitiao()
Dim i As Integer, x As Integer
Dim endrow As Integer
With Sheets(1)
endrow = .Range("a65536").End(xlUp).Row - 1 '测出数据的最后一行
For x = 3 To endrow
i = i + 1
.Rows(1).Copy Sheets(2).Cells(i, 1) '把标题贴过去,如果不需要每个人的都有标题行,把这两行放循环前面
i = i + 1
.Rows(2).Copy Sheets(2).Cells(i, 1) '把每条数据抬头贴过去
i = i + 1
.Rows(x).Copy Sheets(2).Cells(i, 1) '把数据贴过去
i = i + 1 '每条数据空一空行出来,方便你剪成小条,呵呵
Next x
End With
End Sub
Sub gonzitiao()
Dim i As Integer, x As Integer
Dim endrow As Integer
With Sheets(1)
endrow = .Range("a65536").End(xlUp).Row - 1 '测出数据的最后一行
For x = 3 To endrow
i = i + 1
.Rows(1).Copy Sheets(2).Cells(i, 1) '把标题贴过去,如果不需要每个人的都有标题行,把这两行放循环前面
i = i + 1
.Rows(2).Copy Sheets(2).Cells(i, 1) '把每条数据抬头贴过去
i = i + 1
.Rows(x).Copy Sheets(2).Cells(i, 1) '把数据贴过去
i = i + 1 '每条数据空一空行出来,方便你剪成小条,呵呵
Next x
End With
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询