ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   limiting column selection (https://www.excelbanter.com/excel-programming/433128-limiting-column-selection.html)

Rhino V

limiting column selection
 
I have this coded on a worksheet:

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

It allows me to double-click a cell in column A, selects and copies all data
on that row up to column E, and pastes the data into another worksheet.

Unforutnately, if you double-click anywhere else, like a cell in columns B
or C, it does the same thing and selects the next 4 cells over in that row
and copies and pastes it too. How can I limit the code to only execute if
the cell that is double-clicked is in column A?

FSt1

limiting column selection
 
hi
add something like this to your code.......
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Cancel = True ' prevent double-click from causing Edit Mode in cell
Dim r As Range
Set r = Range("A:A")
If Intersect(Target, r) Is Nothing Then
Exit Sub
Else
Application.Run "CopyProcedure"
End If
End Sub

regards
FSt1

"Rhino V" wrote:

I have this coded on a worksheet:

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

It allows me to double-click a cell in column A, selects and copies all data
on that row up to column E, and pastes the data into another worksheet.

Unforutnately, if you double-click anywhere else, like a cell in columns B
or C, it does the same thing and selects the next 4 cells over in that row
and copies and pastes it too. How can I limit the code to only execute if
the cell that is double-clicked is in column A?


Jacob Skaria

limiting column selection
 
Try the below which will limit the code to be executed in ColA

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
If Not Application.Intersect(Target, Range("A:A")) Is Nothing Then _
Application.Run "CopyProcedure"
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Rhino V" wrote:

I have this coded on a worksheet:

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

It allows me to double-click a cell in column A, selects and copies all data
on that row up to column E, and pastes the data into another worksheet.

Unforutnately, if you double-click anywhere else, like a cell in columns B
or C, it does the same thing and selects the next 4 cells over in that row
and copies and pastes it too. How can I limit the code to only execute if
the cell that is double-clicked is in column A?



All times are GMT +1. The time now is 01:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com