Macro to copy formula and paste into another

U

usmc-r70

I found and successfully loaded the following code, but I must use the ENTER
key for it to be fully posted.

Any idea?

Private Sub Worksheet_BeforeDoubleclick(ByVal Target As Range, Cancel As
Boolean)
n = Target.Row
With Target
..Value = Excel.Range("D" & n).Formula
End With
SendKeys "{ENTER}", True
End Sub
 
G

Gary''s Student

You need the SendKeys to get you out of cell edit. You can avoid this by
setting Cancel=True

Private Sub Worksheet_BeforeDoubleclick(ByVal Target As Range, Cancel As
Boolean)
Cancel = True
n = Target.Row
With Target
.Value = Excel.Range("D" & n).Formula
End With
End Sub
 
J

Jacob Skaria

n = Target.Row
With Target
..Value = Excel.Range("D" & n).Formula
End With
Cancel = True

If this post helps click Yes
 
U

usmc-r70

That solution worked, thanks!

Gary''s Student said:
You need the SendKeys to get you out of cell edit. You can avoid this by
setting Cancel=True

Private Sub Worksheet_BeforeDoubleclick(ByVal Target As Range, Cancel As
Boolean)
Cancel = True
n = Target.Row
With Target
.Value = Excel.Range("D" & n).Formula
End With
End Sub
 
U

usmc-r70

That worked as well! Amazing how many different approaches can result in the
same outcome! Thanks to you all from USMC in Iraq.
 
U

usmc-r70

Gary, If I wanted to limit where this code works, (i.e. Column D or a range
of cells) what would the code look like?
 

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