Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

running a macro with a condition

Status
Not open for further replies.

dalex17

Technical User
Jul 14, 2002
96
US
I am in need of a code that will allow a macro to run only when the conditon cell B92 equals cell F96 is met. I guess this would be a sort of "IF" statement that would say if cell B92 = F96, then run macro, else do not run (or something like that).

Here is the catch however: the macro cannot run if the result of the macro creates the condition where cell B92 equals F96. In other words, if B92 equals F96 AFTER the macro runs, then I do not the macro to even run initially.

I hope this makes sense

Dalex
 
No way to generate a complete solution to your problem without seeing the code of your macro first. However:

In the WorkSheet_Change event of the worksheet in question, put the following:

If Range("B92").Value = Range("F96").Value Then
MyMacroName
End If


That should get your code started. The obvious drawback to using that condition is that, as long as the condition is true, it will run your code EVERY time the worksheet is changed (even if it was an unrelated cell that was changed).

Now, if your macro simply calculates a value, your "catch" may not be so difficult to overcome. You can change the Sub to a Function, and test the value your Function returns before you actually write it to the sheet.

If your macro does something else. . . we'd really need to see the code.

HTH!


VBAjedi [swords]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top