ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Running a macro on action (https://www.excelbanter.com/excel-programming/326873-running-macro-action.html)

Andrew

Running a macro on action
 
Hi,

This is probably a simple one but I just cant find the answer. How does one
kick off a macro by a specific cell being altered (eg data keyed into it,
change of font etc)

--
Andrew

Jim Thomlinson[_3_]

Running a macro on action
 
To access the events that are generated on a sheet do this...

Right Click the tab of the sheet - Select View Code
Just above the code window you will see the word general
Change General to Worksheet

Just to the right of Worksheet is a drop down list of all of the events that
you can make your code respond to. Note that when you select the event a code
procedure is created for you automatically... Easy as that. Some of the
procedures will have arguments like Target. Target is the cell you just
changed or selected or...

HTH

"Andrew" wrote:

Hi,

This is probably a simple one but I just cant find the answer. How does one
kick off a macro by a specific cell being altered (eg data keyed into it,
change of font etc)

--
Andrew


Andrew

Running a macro on action
 
Hi Jim,

Thanks for this. It has helped but as soon as I select the cell it starts
the macro, I want to action the macro IF AND ONLY IF it has changed. Below
is what I have so far...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Address = "$C$3" Then
MsgBox ("Cursor has been placed on cell C3.")
End If
End Sub


"Jim Thomlinson" wrote:

To access the events that are generated on a sheet do this...

Right Click the tab of the sheet - Select View Code
Just above the code window you will see the word general
Change General to Worksheet

Just to the right of Worksheet is a drop down list of all of the events that
you can make your code respond to. Note that when you select the event a code
procedure is created for you automatically... Easy as that. Some of the
procedures will have arguments like Target. Target is the cell you just
changed or selected or...

HTH

"Andrew" wrote:

Hi,

This is probably a simple one but I just cant find the answer. How does one
kick off a macro by a specific cell being altered (eg data keyed into it,
change of font etc)

--
Andrew


OJ[_2_]

Running a macro on action
 
Hi,
replace
If ActiveCell.Address = "$C$3" Then
with
If Target.Address = "$C$3" Then

Hth,
OJ


OJ[_2_]

Running a macro on action
 
Hi,
replace
If ActiveCell.Address = "$C$3" Then
with
If Target.Address = "$C$3" Then

Hth,
OJ


Patrick Molloy[_2_]

Running a macro on action
 
you slected the wrong event the. the selection change fires whenever you
select a cell. the change event fires when you enter a new value

try this

Private Sub Worksheet_Change(ByVal Target As Range)
If ActiveCell.Address = "$C$3" Then
MsgBox Target.Value, , "New Value in " & Target.Address
End If
End Sub



"Andrew" wrote:

Hi Jim,

Thanks for this. It has helped but as soon as I select the cell it starts
the macro, I want to action the macro IF AND ONLY IF it has changed. Below
is what I have so far...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Address = "$C$3" Then
MsgBox ("Cursor has been placed on cell C3.")
End If
End Sub


"Jim Thomlinson" wrote:

To access the events that are generated on a sheet do this...

Right Click the tab of the sheet - Select View Code
Just above the code window you will see the word general
Change General to Worksheet

Just to the right of Worksheet is a drop down list of all of the events that
you can make your code respond to. Note that when you select the event a code
procedure is created for you automatically... Easy as that. Some of the
procedures will have arguments like Target. Target is the cell you just
changed or selected or...

HTH

"Andrew" wrote:

Hi,

This is probably a simple one but I just cant find the answer. How does one
kick off a macro by a specific cell being altered (eg data keyed into it,
change of font etc)

--
Andrew



All times are GMT +1. The time now is 02:20 AM.

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