ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro auto run (https://www.excelbanter.com/excel-programming/300591-macro-auto-run.html)

nightshift12

macro auto run
 
is it possible to have a macro run automatically using an "if" statemen


--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

macro auto run
 
If you mean an IF statement in a worksheet, then no. Worksheets can only
call functions that return a result, they cannot run a macro that modifies
the Excel environment.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"nightshift12 " wrote in
message ...
is it possible to have a macro run automatically using an "if" statement
?


---
Message posted from http://www.ExcelForum.com/




Nigel

macro auto run
 
In VBA you can choose which macro to run using any of the conditional
statements, so

If condition then
Call macro1
else
Call macro2
endif

of more simply for just one macro

If condition then call macro1

Cheers
Nigel

"nightshift12 " wrote in
message ...
is it possible to have a macro run automatically using an "if" statement
?


---
Message posted from http://www.ExcelForum.com/




patrick molloy

macro auto run
 
If is a conditional test, and can be in a sheet function
or in code.
In a sheet function, only the content of the calling cell
can be changed - a sheet function cannot alter th evalues
in other cells.

In code, your IF can be in a procedure - sub if you will-
where the called routine can pretty much do whatever you
want.

Now, running a macro automatically means what? If yuo
want code to start when a workbook opens, then use a proc
called Auto_Open or use the workboook's Open event.
If you want code to run when a cell value changes, then
you coul duse the Sheet's Change event - this is fired
when a value is entered. ou could also use the workbook's
SheetCalculate event that is fired when a sheet is
calculated.

Patrick Molloy
Microsoft Excel MVP


-----Original Message-----
is it possible to have a macro run automatically using

an "if" statement
?


---
Message posted from http://www.ExcelForum.com/

.



All times are GMT +1. The time now is 08:00 AM.

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