ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   is it possible to run a macro using a cell reference? (https://www.excelbanter.com/excel-programming/356377-possible-run-macro-using-cell-reference.html)

JasonK

is it possible to run a macro using a cell reference?
 
TIA - everyone that helps in this group is awesome. thanks so much
for your help.


i would like to know, and i can't find it in my books, if it is
possible to run a macro when a cell returns a certain criteria.

for example, if range("A1") = x then application.run "macro1"

if so, where do i put the code?

jasonk

Don Guillett

is it possible to run a macro using a cell reference?
 
right click sheet tabview codeinsert thisSAVE
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" And UCase(Target) = "X" Then MsgBox "HI"
End Sub

--
Don Guillett
SalesAid Software

"JasonK" wrote in message
...
TIA - everyone that helps in this group is awesome. thanks so much
for your help.


i would like to know, and i can't find it in my books, if it is
possible to run a macro when a cell returns a certain criteria.

for example, if range("A1") = x then application.run "macro1"

if so, where do i put the code?

jasonk




Tom Ogilvy

is it possible to run a macro using a cell reference?
 
What will make the value change?

If by editing use the Worksheet_Change event
if by formula, use the Worksheet_Calculate event

You get to these by right clicking on the sheet tab and selecting view code.

In the resulting module, in the dropdowns at the top
Left: Worksheet
Right: Change (or Calculate)

this places an event procedure definition in the module.

In the Change event, the Target argument contains a reference to the cell
that triggered the change (was edited usually). Calculate doesn't give you
that information.

Any cell that is changed by editing will trigger the Change event. So in
the event, you put code to determine whether to react or not

With calculate, you will need to determine whether you need to act or not.
If it is something to do over and over, then no problem. But if you only
want to do it once when the value changes, you will need to store information
- perhaps in static variables.

See Chip Pearson's page on events:

http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy

"JasonK" wrote:

TIA - everyone that helps in this group is awesome. thanks so much
for your help.


i would like to know, and i can't find it in my books, if it is
possible to run a macro when a cell returns a certain criteria.

for example, if range("A1") = x then application.run "macro1"

if so, where do i put the code?

jasonk


JasonK

is it possible to run a macro using a cell reference?
 
thank you gentlemen, i appreciate the help.
the first code didn't work for me, but after reading this response,
i'm messing around with the advice and i believe i can make it work.

thanks again,
jasonk


On Fri, 17 Mar 2006 14:10:27 -0800, Tom Ogilvy
wrote:

What will make the value change?

If by editing use the Worksheet_Change event
if by formula, use the Worksheet_Calculate event

You get to these by right clicking on the sheet tab and selecting view code.

In the resulting module, in the dropdowns at the top
Left: Worksheet
Right: Change (or Calculate)

this places an event procedure definition in the module.

In the Change event, the Target argument contains a reference to the cell
that triggered the change (was edited usually). Calculate doesn't give you
that information.

Any cell that is changed by editing will trigger the Change event. So in
the event, you put code to determine whether to react or not

With calculate, you will need to determine whether you need to act or not.
If it is something to do over and over, then no problem. But if you only
want to do it once when the value changes, you will need to store information
- perhaps in static variables.

See Chip Pearson's page on events:

http://www.cpearson.com/excel/events.htm




All times are GMT +1. The time now is 05:35 AM.

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