Macro to Copy Info to the Active Cell

mpalmer

New Member
Joined
Nov 17, 2004
Messages
15
I am new to macros and cannot figure this out. I have a range of cells that are fixed on the worksheet. I want to click on a blank cell - then use a macsro to go to the fixed range - copy the range and paste it back to blank cell (active) that i started in. Sure its easy for you guys but its tearing me up! Thanks in advance for any suggestions....
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Code:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim rng As Range
Set rng = Sheets("Sheet1").Range(Cells(1, 1), Cells(1, 5)) 'your fixed range (here A1:A5)
With rng
    .Copy
    Target.PasteSpecial xlPasteValues
End With
Application.CutCopyMode = False
End Sub

Assumes you're pasting data into the same sheet on which the fixed data is stored

It will also fire everytime you double click on a cell -- if you want a fail-safe you could put a msgbox into the code before activating the copy / paste routine to get confirmation from end-user ... eg

Code:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
If MsgBox("Copy Range?",vbyesno,"Copy Confirm") = vbno then exit sub
Dim rng As Range
Set rng = Sheets("Sheet1").Range(Cells(1, 1), Cells(1, 5)) 'your fixed range (here A1:A5)
With rng
    .Copy
    Target.PasteSpecial xlPasteValues
End With
Application.CutCopyMode = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,696
Members
449,048
Latest member
81jamesacct

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