0

我是在 Excel 中创建宏的新手,我处于一个困难的境地。我有一个 48 列和 6000 多行的工作表。我必须从 20 列和所有行中检索选择数据,并将它们放入 3 列和相等行数的表中。例如,复制 Sheet1:A2、E1、E3 并粘贴到新的 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

请帮我。

4

1 回答 1

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,但我没有。

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

于 2013-07-10T19:12:55.457 回答