Ana DEV
Ana DEV

Reputation: 1030

How to Copy Data from One sheet to another

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

Answers (2)

Neelesh
Neelesh

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

nicolò grando
nicolò grando

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

Related Questions