ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro launches after activating a range of cells (https://www.excelbanter.com/excel-programming/320187-macro-launches-after-activating-range-cells.html)

Martin

Macro launches after activating a range of cells
 
I would like to run a macro upon the selection of a cell within a given range.
The following code works, but runs the macro upon selection of the entire
column...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 5 Then LayoutType.Show
End Sub

So I wondering if something along the lines of...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Range = E6:E1006 Then LayoutType.Show
End Sub

.... however this doesn't work

Any help with this would be appreciated

William[_2_]

Macro launches after activating a range of cells
 
Hi Martin

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Sheets("Sheet1")
If Not Intersect(Target, .Range("E6:E1006 ")) Is Nothing Then
LayoutType.Show
End If
End With
End Sub

--
XL2002
Regards

William



"Martin" wrote in message
...
| I would like to run a macro upon the selection of a cell within a given
range.
| The following code works, but runs the macro upon selection of the entire
| column...
|
| Private Sub Worksheet_SelectionChange(ByVal Target As Range)
| If Target.Column = 5 Then LayoutType.Show
| End Sub
|
| So I wondering if something along the lines of...
|
| Private Sub Worksheet_SelectionChange(ByVal Target As Range)
| If Target.Range = E6:E1006 Then LayoutType.Show
| End Sub
|
| ... however this doesn't work
|
| Any help with this would be appreciated



Martin

Macro launches after activating a range of cells
 
Thanks

"William" wrote:

Hi Martin

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Sheets("Sheet1")
If Not Intersect(Target, .Range("E6:E1006 ")) Is Nothing Then
LayoutType.Show
End If
End With
End Sub

--
XL2002
Regards

William



"Martin" wrote in message
...
| I would like to run a macro upon the selection of a cell within a given
range.
| The following code works, but runs the macro upon selection of the entire
| column...
|
| Private Sub Worksheet_SelectionChange(ByVal Target As Range)
| If Target.Column = 5 Then LayoutType.Show
| End Sub
|
| So I wondering if something along the lines of...
|
| Private Sub Worksheet_SelectionChange(ByVal Target As Range)
| If Target.Range = E6:E1006 Then LayoutType.Show
| End Sub
|
| ... however this doesn't work
|
| Any help with this would be appreciated





All times are GMT +1. The time now is 12:46 AM.

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