Help Pasting

judgejustin

Board Regular
Joined
Mar 3, 2014
Messages
139
This code works up to the point of pasting. It is suppose to paste the copied cell range to the cell that was double clicked in the original workbook. Any thoughts?
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim OpenBook As Workbook
Dim spath As String

If Target.Column <> 14 Then Exit Sub
spath = ThisWorkbook.Path & "\"
Application.ScreenUpdating = False

Set OpenBook = Workbooks.Open(Filename:=spath & ActiveCell.Offset(, -11) & ".xlsm", UpdateLinks:=True)

With OpenBook

.Sheets("AGR").Range("K11").Copy

      ThisWorkbook.Worksheets("Statistics").Target.PasteSpecial xlPasteValues
        .Sheets("AGR").Range("K9").Copy
        ThisWorkbook.Worksheets("Statistics").Target.Offset(, 1).PasteSpecial xlPasteValues
        .Close True
    End With
    
    Application.ScreenUpdating = True

End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try this

VBA Code:
    Dim spath As String
    If Target.Column <> 14 Then Exit Sub
    Application.ScreenUpdating = False
    spath = ThisWorkbook.Path & "\"
   
    Cancel = True
    With Workbooks.Open(Filename:=spath & ActiveCell.Offset(, -11) & ".xlsm", UpdateLinks:=True)
        Target.Resize(, 2) = Array(.Sheets("AGR").Range("K11"), .Sheets("AGR").Range("K9"))
        .Close True
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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