ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   run macro on selection change (https://www.excelbanter.com/excel-programming/357928-run-macro-selection-change.html)

tony

run macro on selection change
 
I would like to execute my macro when I will modify data in selected cell. I
would like to use selection change even as the trigger. How I can do it ?
Thanks for help.

Tony

Tom Ogilvy

run macro on selection change
 
right click on the sheet tab and select view code. In the left dropdown
select worksheet. In the right dropdown, select selectionchange

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

End Sub

put your commands there.

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error goto ErrHandler
If target.Address = "$A$9" then
Application.EnableEvents = False


End If


ErrHandler:
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy


"Tony" wrote in message
...
I would like to execute my macro when I will modify data in selected cell.

I
would like to use selection change even as the trigger. How I can do it ?
Thanks for help.

Tony




tony

run macro on selection change
 
Hi Tom,

Thank you for help. But it is not exactly what I need. I would like the
macro to execute when I am leaving this cell, not when I am entering. Could
you please help me a bit more. Thank you.

Regards,

Tony

"Tom Ogilvy" wrote:

right click on the sheet tab and select view code. In the left dropdown
select worksheet. In the right dropdown, select selectionchange

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

End Sub

put your commands there.

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error goto ErrHandler
If target.Address = "$A$9" then
Application.EnableEvents = False


End If


ErrHandler:
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy


"Tony" wrote in message
...
I would like to execute my macro when I will modify data in selected cell.

I
would like to use selection change even as the trigger. How I can do it ?
Thanks for help.

Tony





Tom Ogilvy

run macro on selection change
 
A start would be to not say selectionchange when you mean Change <g:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error goto ErrHandler
If target.Address = "$A$9" then
Application.EnableEvents = False


End If


ErrHandler:
Application.EnableEvents = True
End Sub


--
Regards,
Tom Ogilvy


"Tony" wrote in message
...
Hi Tom,

Thank you for help. But it is not exactly what I need. I would like the
macro to execute when I am leaving this cell, not when I am entering.

Could
you please help me a bit more. Thank you.

Regards,

Tony

"Tom Ogilvy" wrote:

right click on the sheet tab and select view code. In the left dropdown
select worksheet. In the right dropdown, select selectionchange

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

End Sub

put your commands there.

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error goto ErrHandler
If target.Address = "$A$9" then
Application.EnableEvents = False


End If


ErrHandler:
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy


"Tony" wrote in message
...
I would like to execute my macro when I will modify data in selected

cell.
I
would like to use selection change even as the trigger. How I can do

it ?
Thanks for help.

Tony







tony

run macro on selection change
 
Thank you for help. I have it working now.

Regards,

Tony

"Tom Ogilvy" wrote:

A start would be to not say selectionchange when you mean Change <g:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error goto ErrHandler
If target.Address = "$A$9" then
Application.EnableEvents = False


End If


ErrHandler:
Application.EnableEvents = True
End Sub


--
Regards,
Tom Ogilvy


"Tony" wrote in message
...
Hi Tom,

Thank you for help. But it is not exactly what I need. I would like the
macro to execute when I am leaving this cell, not when I am entering.

Could
you please help me a bit more. Thank you.

Regards,

Tony

"Tom Ogilvy" wrote:

right click on the sheet tab and select view code. In the left dropdown
select worksheet. In the right dropdown, select selectionchange

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

End Sub

put your commands there.

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error goto ErrHandler
If target.Address = "$A$9" then
Application.EnableEvents = False


End If


ErrHandler:
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy


"Tony" wrote in message
...
I would like to execute my macro when I will modify data in selected

cell.
I
would like to use selection change even as the trigger. How I can do

it ?
Thanks for help.

Tony








All times are GMT +1. The time now is 11:06 PM.

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