Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default 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....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default 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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default 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





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default 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







  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default 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








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to transfer contents of 'Selected' cell to alternate cell. Gryndar Excel Worksheet Functions 7 December 20th 08 09:58 PM
Cell Selected to run Macro Corey Excel Programming 2 October 31st 06 04:26 AM
Macro to start when cell selected JackR Excel Discussion (Misc queries) 5 March 20th 06 04:01 PM
run macro when cell is selected beauty_bobaloo Excel Worksheet Functions 9 January 30th 06 11:11 PM
Macro to take selected cells times a selected cell Craig Excel Programming 4 October 24th 05 12:54 AM


All times are GMT +1. The time now is 04:38 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"