How to Copy Data from One sheet to another

2019-09-04 05:23发布

I want to copy the data from specific cells from one sheet to another sheet's specific cells.

This is the code I tried

Private Sub CommandButton1_Click()
Sheets("KeyInformation").Select
Range("A2:Q2").Select
Range("A2:Q2").Copy

Sheets("Factsheet").Select
Range("B9:B25").Select
ActiveSheet.Paste
Sheets("Factsheet").Select
End Sub

It copied. How can I paste where I want?

标签: excel vba
2条回答
小情绪 Triste *
2楼-- · 2019-09-04 05:46

Avoid using select.

Private Sub CommandButton1_Click()
Dim ws, ws1 As Worksheet
Set ws = Sheets("KeyInformation")
Set ws1 = Sheets("Factsheet")
ws.Range("A2:Q2").Copy
ws1.Range("B9").PasteSpecial Paste:=xlPasteAll, Transpose:=True
Application.CutCopyMode = False
ws1.Activate
End Sub
查看更多
Animai°情兽
3楼-- · 2019-09-04 05:53

if you want only to copy the row in the the new sheet in the same position, you have to declare the position where you want to paste the copied row:

Private Sub CommandButton1_Click()
Sheets("KeyInformation").Select
Range("A2:Q2").Select
Range("A2:Q2").Copy

Sheets("Factsheet").Select
' Find the last row of data
Range("A2:Q2").Select
ActiveSheet.Paste
Sheets("Factsheet").Select
End Sub
查看更多
登录 后发表回答