使用VBA将特定列从1个Excel工作表复制到另一个

时间:2016-12-07 20:30:33

标签: excel vba excel-vba

我在下面的公式中说明它应该将我拥有的1个工作表的特定列转移到我在第2个工作表中指定的列。然而,一切都没有发生。真的很感激一些帮助!

Sub copycolumns()
Dim lastrow As Long, erow As Long

lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row

For i = 2 To lastrow
Sheet1.Cells(i, 2).Copy
airow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Sheet1.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 1)

Subscriber.Cells(i, 1).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 2)

Subscriber.Cells(i, 3).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 3)

Subscriber.Cells(i, 4).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 4)

Subscriber.Cells(i, 5).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 5)

Subscriber.Cells(i, 6).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 6)

Subscriber.Cells(i, 11).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 25)

Subscriber.Cells(i, 12).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 26)

Subscriber.Cells(i, 13).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 27)

Subscriber.Cells(i, 14).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 28)

Subscriber.Cells(i, 16).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 19)

Subscriber.Cells(i, 17).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 7)

Subscriber.Cells(i, 18).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 9)

Subscriber.Cells(i, 19).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 13)

Subscriber.Cells(i, 20).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 14)

Subscriber.Cells(i, 23).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 15)

Subscriber.Cells(i, 24).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 16)

Subscriber.Cells(i, 25).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 10)

Subscriber.Cells(i, 26).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 11)

Subscriber.Cells(i, 27).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 12)

Subscriber.Cells(i, 29).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 31)

Subscriber.Cells(i, 30).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 17)

Subscriber.Cells(i, 31).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 22)

Subscriber.Cells(i, 32).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 23)

Subscriber.Cells(i, 33).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 18)

Subscriber.Cells(i, 33).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 32)

Subscriber.Cells(i, 38).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 24)

Subscriber.Cells(i, 42).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 29)

Subscriber.Cells(i, 44).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 30)

Subscriber.Cells(i, 46).Copy
Subscriber.Paste Destination:=Worksheets(“Sheet1”).Cells(airow, 3)

Next i

Application.CutCopyMode = False

Range(“A1”).Select

End Sub

0 个答案:

没有答案