View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default specifying the column for double click

One more...

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)

'this probably isn't necessary, but it doesn't hurt
if target.cells.count 1 then
exit sub
end if

if intersect(target, me.range("A:a")) is nothing then
exit sub
end if

'only cancel if you're in column A
Cancel = True ' prevent double-click from causing Edit Mode in cell
Call CopyProcedure(mycell:=target) 'why use application.run???

End Sub

Sub CopyProcedure(myCell as range)

dim DestCell as range

with worksheets("report")
set destcell = .cells(.rows.count,"A").end(xlup).offset(1,0)
end with

mycell.resize(1,5).copy
destcell.pastespecial Paste:=xlPasteValues, _
Operation:=xlNone, skipBlanks:=False, _
Transpose:=False
End Sub

=======
You may want to consider being more forgiving. Let them doubleclick on any
column in that row.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)

'this probably isn't necessary, but it doesn't hurt
if target.cells.count 1 then
exit sub
end if

'only cancel if you're in column A
Cancel = True ' prevent double-click from causing Edit Mode in cell
Call CopyProcedure(mycell:=target.entirerow.cells(1))

End Sub

(the other procedure doesn't change.)

(all untested, uncompiled. Watch for typos.)


Rhino V wrote:

Thanks to the generous contriutors here, I have the following code which
copies data from one sheet to another:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Cancel = True ' prevent double-click from causing Edit Mode in cell
Application.Run "CopyProcedure"
End Sub

Sub CopyProcedure()
ActiveCell.Range("A1:E1").Select
Selection.Copy
Sheets("Report").Activate
mlastrow = Cells(Rows.Count, "A").End(xlUp).Row
Cells(mlastrow + 1, "A").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub

It works great except for one little thing: because it's supposed to copy
data from columns A to E of the same row when you double-click any cell in
coumn A, it also will copy the corresponding five adjacent cells no matter
where you double-click on the sheet.
How can I limit the code so that only when what is double-clicked is in
column A will the maco activate?
Thanx for any help anyone can provide on this.


--

Dave Peterson