Nick has attended:
Excel Advanced course
Excel and Macros
When using an IF function in excel can you initiate a Macro in the true or false statement?
RE: Excel and Macros
Hi Nick, Thank you for your post, welcome to the forum, the answer to your question is; NO, The reason you cannot have a formula like =IF(A1>10,MyMacro,0)in a worksheet cell is because Excel must keep track of which cells are dependents and precedents of which other cells. It must do this in order to calculate the worksheet in the proper order. VBA code which could change worksheet cells could irreversible confuse the order of calculations. Therefore, Excel forbids code called from a worksheet cell from changing anything in the Excel environment. A FUNCTION procedure can only return a value to Excel, nothing more.
However, you could use the worksheet's Change event to do something like this.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Application.Intersect(Target, Range("A1")) Is Nothing Then
If Target.Value > 10 Then MsgBox "Put Your Code Here"
End If
End If
End Sub
regards Pete