将选择数据从一个工作表复制到新工作表

时间:2013-07-10 19:00:58

标签: excel-vba copy-paste vba excel

我是在Excel中创建宏的新手,我处境艰难。我有一个48列和6000多行的woorksheet。我必须从20列和所有行中检索选择数据,并将它们放入3列和相同行数的表中。例如Copy Sheet1:A2,E1,E3和Paste into New Sheet3:A2,B2,C2。由于电子表格的大小需要自动化,以及数据未格式化为直接复制的事实

我使用以下脚本收到错误424(对象需要)。

Private Sub CommandButton1_Click()
Dim Counter As Integer
Counter = 3
Counter_H = 2
Do Until ThisWorkbook.Sheets("MASTER_LEAK_REPAIRS_CY2012").Cells(Counter, 4).Value     = " "
thisworkbooks.Sheets("Sheet1").Select("A" & Counter, "B" & Counter, "C" &      Counter).Value = thisworkbooks.Sheets("MASTER_LEAK_REPAIRS_CY2012").Select("D" & Counter, "Q" & (Counter - Counter_H), "Q" & Counter).Value
    Counter = Counter + 1
    Counter_H = Counter + 1
Loop
End Sub

请帮帮我。

1 个答案:

答案 0 :(得分:0)

基于以下评论的新答案。

Private Sub CommandButton1_Click()
Dim Counter As Integer
Counter = 3
Counter_H = 2

Do Until ThisWorkbook.Sheets("MASTER_LEAK_REPAIRS_CY2012").Cells(Counter, 4).Value = ""
    ThisWorkbook.Sheets("Sheet1").Range("A" & Counter) = ThisWorkbook.Sheets("MASTER_LEAK_REPAIRS_CY2012").Range("D" & Counter)    
    ThisWorkbook.Sheets("Sheet1").Range("B" & Counter) = ThisWorkbook.Sheets("MASTER_LEAK_REPAIRS_CY2012").Range("Q" & (Counter - Counter_H)) 
    ThisWorkbook.Sheets("Sheet1").Range("C" & Counter) = ThisWorkbook.Sheets("MASTER_LEAK_REPAIRS_CY2012").Range("Q" & Counter)
    Counter = Counter + 1
    Counter_H = Counter + 1
Loop
End Sub

当我尝试原创时,我收到错误450,但是我没有。

如果您有任何问题,请告诉我们!