ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run macro when cell is selected (https://www.excelbanter.com/excel-programming/400164-run-macro-when-cell-selected.html)

Corey

Run macro when cell is selected
 
I know how to rtun a macro if a cell value is changed like :
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C5")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring has changed!
'Do whatever you need to do...
End If
End SubBut how can i have a macro run if the cell is simply Selected instead ?Corey....



Dave Peterson

Run macro when cell is selected
 
You can tie into a different event: Worksheet_SelectionChange



Corey wrote:

I know how to rtun a macro if a cell value is changed like :
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C5")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring has changed!
'Do whatever you need to do...
End If
End SubBut how can i have a macro run if the cell is simply Selected instead ?Corey....


--

Dave Peterson

Corey

Run macro when cell is selected
 
Thanks Dave.
"Dave Peterson" wrote in message
...
You can tie into a different event: Worksheet_SelectionChange



Corey wrote:

I know how to rtun a macro if a cell value is changed like :
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C5")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring has changed!
'Do whatever you need to do...
End If
End SubBut how can i have a macro run if the cell is simply Selected instead ?Corey....


--

Dave Peterson



Corey

Run macro when cell is selected
 
Is there a way to NOT run the code i ended up with IF there is MORE THAN 1 cell selected ?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("B5")) Is Nothing Then
Exit Sub
Else
UserForm2.Show
End If
End Sub

I use another macro to email the sheet, but as the B5 cell is inside the sheet range it rund the
macro again.

Is there a way around this ?

Corey....



"Dave Peterson" wrote in message
...
You can tie into a different event: Worksheet_SelectionChange



Corey wrote:

I know how to rtun a macro if a cell value is changed like :
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C5")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring has changed!
'Do whatever you need to do...
End If
End SubBut how can i have a macro run if the cell is simply Selected instead ?Corey....


--

Dave Peterson



Gary Keramidas

Run macro when cell is selected
 
you can give this a try


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
If Intersect(Target, Range("B5")) Is Nothing Then
Exit Sub
Else
UserForm2.Show
End If
end if
End Sub

--


Gary


"Corey" wrote in message
...
Is there a way to NOT run the code i ended up with IF there is MORE THAN 1
cell selected ?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("B5")) Is Nothing Then
Exit Sub
Else
UserForm2.Show
End If
End Sub

I use another macro to email the sheet, but as the B5 cell is inside the sheet
range it rund the
macro again.

Is there a way around this ?

Corey....



"Dave Peterson" wrote in message
...
You can tie into a different event: Worksheet_SelectionChange



Corey wrote:

I know how to rtun a macro if a cell value is changed like :
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C5")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring has changed!
'Do whatever you need to do...
End If
End SubBut how can i have a macro run if the cell is simply Selected instead
?Corey....


--

Dave Peterson





Corey

Run macro when cell is selected
 
Gary,
Thanks for the reply.

The macro does not seem to run when i use it now ??
Even if the B5 is the ONLY cell selected.

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
you can give this a try


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
If Intersect(Target, Range("B5")) Is Nothing Then
Exit Sub
Else
UserForm2.Show
End If
end if
End Sub

--


Gary


"Corey" wrote in message
...
Is there a way to NOT run the code i ended up with IF there is MORE THAN 1
cell selected ?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("B5")) Is Nothing Then
Exit Sub
Else
UserForm2.Show
End If
End Sub

I use another macro to email the sheet, but as the B5 cell is inside the sheet
range it rund the
macro again.

Is there a way around this ?

Corey....



"Dave Peterson" wrote in message
...
You can tie into a different event: Worksheet_SelectionChange



Corey wrote:

I know how to rtun a macro if a cell value is changed like :
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C5")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring has changed!
'Do whatever you need to do...
End If
End SubBut how can i have a macro run if the cell is simply Selected instead
?Corey....


--

Dave Peterson






Gary Keramidas

Run macro when cell is selected
 
as soon as i select B5, the userform is displayed. if i select any other cell or
select more than one cell along with B5 it does not display.

--


Gary


"Corey" wrote in message
...
Gary,
Thanks for the reply.

The macro does not seem to run when i use it now ??
Even if the B5 is the ONLY cell selected.

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
you can give this a try


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
If Intersect(Target, Range("B5")) Is Nothing Then
Exit Sub
Else
UserForm2.Show
End If
end if
End Sub

--


Gary


"Corey" wrote in message
...
Is there a way to NOT run the code i ended up with IF there is MORE THAN 1
cell selected ?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("B5")) Is Nothing Then
Exit Sub
Else
UserForm2.Show
End If
End Sub

I use another macro to email the sheet, but as the B5 cell is inside the
sheet
range it rund the
macro again.

Is there a way around this ?

Corey....



"Dave Peterson" wrote in message
...
You can tie into a different event: Worksheet_SelectionChange



Corey wrote:

I know how to rtun a macro if a cell value is changed like :
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C5")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring has changed!
'Do whatever you need to do...
End If
End SubBut how can i have a macro run if the cell is simply Selected instead
?Corey....


--

Dave Peterson








Corey

Run macro when cell is selected
 
That's strange.
I can selecte ANY cell including B5 and i do not get the userform with :
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
If Intersect(Target, Range("B5")) Is Nothing Then
Exit Sub
Else
UserForm2.Show
End If
End If
End Sub

If i use :

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("B5")) Is Nothing Then
Exit Sub
Else
UserForm2.Show
End If
End Sub
I get the userform when selecting B5 but ALSO get it if i select a number of cells including B5 in
them.

Why would this be ?

Corey....
"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
as soon as i select B5, the userform is displayed. if i select any other cell or
select more than one cell along with B5 it does not display.

--


Gary


"Corey" wrote in message
...
Gary,
Thanks for the reply.

The macro does not seem to run when i use it now ??
Even if the B5 is the ONLY cell selected.

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
you can give this a try


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
If Intersect(Target, Range("B5")) Is Nothing Then
Exit Sub
Else
UserForm2.Show
End If
end if
End Sub

--


Gary


"Corey" wrote in message
...
Is there a way to NOT run the code i ended up with IF there is MORE THAN 1
cell selected ?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("B5")) Is Nothing Then
Exit Sub
Else
UserForm2.Show
End If
End Sub

I use another macro to email the sheet, but as the B5 cell is inside the
sheet
range it rund the
macro again.

Is there a way around this ?

Corey....



"Dave Peterson" wrote in message
...
You can tie into a different event: Worksheet_SelectionChange



Corey wrote:

I know how to rtun a macro if a cell value is changed like :
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C5")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring has changed!
'Do whatever you need to do...
End If
End SubBut how can i have a macro run if the cell is simply Selected instead
?Corey....


--

Dave Peterson










All times are GMT +1. The time now is 10:30 AM.

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