Reputation: 1030
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?
Upvotes: 0
Views: 23854
Reputation: 138
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
Upvotes: 3
Reputation: 407
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
Upvotes: 0