Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro to transfer contents of 'Selected' cell to alternate cell. | Excel Worksheet Functions | |||
Cell Selected to run Macro | Excel Programming | |||
Macro to start when cell selected | Excel Discussion (Misc queries) | |||
run macro when cell is selected | Excel Worksheet Functions | |||
Macro to take selected cells times a selected cell | Excel Programming |