Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Davidrowland88
 
Posts: n/a
Default can i use an IF Statement to run a macro?

i am using excel 2000. I want to know if you can use an IF Statement to run a
macro. E.G If a cell equals 1 then run a certain macro
  #2   Report Post  
JE McGimpsey
 
Posts: n/a
Default

No, in general, formulas can only return values to their calling cells.
However, you can use an event macro that will check your cell each time
the sheet is calculated, say, and run the macro if the value of the cell
is 1. Put this in your worksheet code module (right-click the worksheet
tab and choose View Code):

Private Sub Worksheet_Calculate()
If Range("A1").Value = 1 Then MyMacro
End Sub

where MyMacro is the name of your macro.


In article ,
"Davidrowland88" wrote:

i am using excel 2000. I want to know if you can use an IF Statement to run a
macro. E.G If a cell equals 1 then run a certain macro

  #3   Report Post  
Ron Rosenfeld
 
Posts: n/a
Default

On Fri, 11 Feb 2005 04:25:02 -0800, "Davidrowland88"
wrote:

i am using excel 2000. I want to know if you can use an IF Statement to run a
macro. E.G If a cell equals 1 then run a certain macro


By IF statement I assume you mean the IF worksheet function; and not an IF
statement within the macro itself.

Probably not as a worksheet function cannot change another cell.

However, you could set up your macro as an event-triggered macro, and within
the macro test to see if the cell equals 1.


--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If statement in a Macro Dave Excel Discussion (Misc queries) 1 January 29th 05 12:17 AM
how do i change the expense statement template macro Mad2691 Excel Worksheet Functions 1 January 28th 05 01:21 PM
if statement in Macro John Excel Worksheet Functions 6 December 29th 04 07:17 PM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM
Can you run a macro from an if statement in excel? mstr.cheif Excel Worksheet Functions 3 November 7th 04 09:22 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"