Newbie Q? Double click event to copy and paste relative reference to next empty row in another sheet

OTOTO

Board Regular
Joined
Dec 23, 2013
Messages
209
Here's my problem: I am attempting to make cells in row Q double clickable and in doing so copy the data in that same row (to the left 4 cells to 15 cells to the left (of the double clickable cell)) into columns B through M in another sheet "RiskRegister" in the next empty row. I have found this code for locating the next empty cell in a column for the pasting code:

lMaxRows = Cells(Rows.Count, "B").End(xlUp).Row
Range("B" & lMaxRows +1).select

I have the following code entered into the Worksheet's double click event:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address Like "$Q*" Then
currRow = Target.Cells(1, 1).row
Set currSheet = Target.Worksheet
End If
End Sub

...and I've recorded using relative references the following flawed Macro to run upon the double click:

Sub Macro17()
'
' Macro17 Macro
'

'
ActiveCell.Offset(0, -15).Range("A1:L1").Select
ActiveCell.Offset(0, -4).Range("A1").Activate
Selection.Copy
Sheets("Risk Register").Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End Sub

The debugger is showing that the following line has an error as the identifier under the cursor is not recognized:
ActiveCell.Offset(0, -4).Range("A1").Activate



I am new to working with Excel in this manner and have no coding experience. Any help on how to get this double click event to do what I want would be greatly appreciated.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You don't need to do all the selecting and activating, and you don't need a separate macro to transfer the data.
Try this:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim lMaxRows As Long
If Not Intersect(Target, Columns("Q")) Is Nothing Then
    Range(Cells(Target.Row, "B"), Cells(Target.Row, "M")).Copy
    With Sheets("RiskRegister")
        lMaxRows = .Cells(Rows.Count, "B").End(xlUp).Row
        .Range("B" & lMaxRows + 1).PasteSpecial Paste:=xlPasteAll
        Application.CutCopyMode = False
    End With
End If
End Sub
 
Upvote 0
Thanks JoeMo, that worked like a charm.

Maybe you can assist in my second code question:

Similarly to this task I would like to create a double click event which will look at Column A's data in the row which was selected, Column A contains a number which matches only one other cell in Column A of the worksheet "RiskRegister". This will be used to find the row in the "RiskRegister" sheet which will be updated. I want the doubleclick event to paste data from the sheet with the double click event into the riskregister Sheet but only some columns in the row will have data which needs to be pasted. If there's data it will need to be pasted, if not, then the data in the row in the "RiskRegister" sheet can remain. This is far too complex for me to attempt to solve.
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top