ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Automatically running macros (https://www.excelbanter.com/excel-programming/292336-automatically-running-macros.html)

Jonathan Vickers

Automatically running macros
 
Hi,

How can I make a macro automatically run when any cell in a particular
column is selected?

Thanks for any help,

Jon



Tom Ogilvy

Automatically running macros
 
Right click on the sheet tab and select view code

put in code like this

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
if Target.count 1 then exit sub
if Target.column = 3 then
nameofyourmacro
End if
End Sub

3 is column C. Change to identify your column.

If your macro will change the selection, you might want to disable events

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
if Target.count 1 then exit sub
On Error goto ErrHandler
if Target.column = 3 then
Application.EnableEvents = False
nameofyourmacro
End if
ErrHandler:
Application.EnableEvents = True
End Sub


--
Regards,
Tom Ogilvy


"Jonathan Vickers" wrote in message
...
Hi,

How can I make a macro automatically run when any cell in a particular
column is selected?

Thanks for any help,

Jon






All times are GMT +1. The time now is 03:40 PM.

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