Copy from ActiveRow, Paste to A2 in Another Sheet

R

ryguy7272

I am trying to copy a row (could be any row) from a sheet named ‘Master’ and
paste to another sheet, named ‘Summary’, in the same workbook, and
PasteSpecial in Cell A2.

Below is the code that I'm trying to implement:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Dim Currrow As Range
Currrow = Range("A2" & .Row & ":V" & .Row)
Worksheets("Master").Range("A" & Currrow & ":V" & Currrow).Copy
Worksheets("Summary").Range("A2").PasteSpecial
End Sub

It would be the entire row; doesn't matter. The data goes from A:V.

Thanks,
Ryan---
 
J

Jacob Skaria

A bit confusing. Do you mean copy a single row (which is the target row) and
is sheet Master the active sheet . Then try the below. Event for master sheet

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Cancel = True
Application.EnableEvents = False
Rows(Target.Row).Copy
Sheets("Summary").Range("A2").PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
'OR to copy with formats
'Rows(Target.Row).Copy Sheets("Summary").Range("A2")
'Application.EnableEvents = True
End Sub

If this post helps click Yes
 
J

Jacob Skaria

If you are looking to copy only the values the below single line would do

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Application.EnableEvents = False
Sheets("Summary").Rows(2) = Rows(Target.Row).Value
Application.EnableEvents = True: Cancel = True
End Sub

If this post helps click Yes
 
R

ryguy7272

Thanks Jacob! I see that you've got the gold now!!

The first macro worked one time, but didn't work any subsequent times. The
Second macro didn't work. Seems to be something preventing it from working.
Is there some way to reset the macro. Also, I tried to clear the contents of
sheet 'Summary' row2, but now I get an error. Must be something with the
event-driven nature of the macro that I don't understand.

Working with this now:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Sheets("Summary").Select
Rows("2:2").Select ' < -- error occurs here
Selection.ClearContents
Sheets("Master").Select
Cancel = True
Application.EnableEvents = False
Rows(Target.Row).Copy
Sheets("Summary").Range("A2").PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
'OR to copy with formats
'Rows(Target.Row).Copy Sheets("Summary").Range("A2")
'Application.EnableEvents = True
End Sub

This must be an easy fix, right.

Thanks,
Ryan---
 
J

Jacob Skaria

Accidently I have marked the last line of the first macro. So unmark that
line. and in your immediate window paste that line and enter so that events
are enabled...Now try all 3 options (2 options mentioned in the 1st post)

Application.EnableEvents = True


If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top