VBA question

Lea

Board Regular
Joined
Oct 1, 2007
Messages
133
Office Version
  1. 365
Platform
  1. Windows
Hello all,
Is it possible to write code in Visual Basic to do the following:

When I double click on a cell in the range A6:A11 the contents of that cell will be copied to cell A5.

It seems like this should be possible but I don't know how.

Thanks,
Lea
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try this: right click the sheet's tab, select View Code and paste in

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A6:A11")) Is Nothing Then Exit Sub
Cancel = True
Range("A5").Value = Target.Value
End Sub
 
Upvote 0
My gut tells me maybe not double click, but on button click. What do the contents of A6:A11 look like
 
Upvote 0
Right click the tab, choose 'view code' and paste in the following:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Target, Range("A6:A11")) Is Nothing Then
        Cancel = True
        Range("A5").Value = Target.Value
    End If
End Sub
 
Upvote 0
VoG, Weaver and rguy84,
Thank you for the help! The code worked on a double click.
Hope you have a great day... you just made mine!
Lea
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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