Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Worksheet Functions / February 2008

Tip: Looking for answers? Try searching our database.

Running a Macro from a Spreadsheet Function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick (GVC) - 10 Feb 2008 00:19 GMT
Does anyone know a method of calling/running a macro from within a cell
function (e.g. a logical IF function)? I am currently using XP Office with
Excel 2002.
Gord Dibben - 10 Feb 2008 00:37 GMT
You can't run a macro from an Excel IF function.

You may be able to run a macro from event code that is triggered by the results
of an IF calculation.

More details would be in order but here is sample sheet event code that runs on
the results of an IF

A1 fomula is  =B1 * C1

Private Sub Worksheet_Calculate()
   On Error GoTo stoppit
       Application.EnableEvents = False
          With Me.Range("A1")
             If .Value <> 144 Then
       MsgBox "Please be advised that A1 does not equal the correct amount."
   'Call "your macro name" to be used instead of the msgbox
    End If
  End With
stoppit:
Application.EnableEvents = True
End Sub

Gord Dibben  MS Excel MVP

>Does anyone know a method of calling/running a macro from within a cell
>function (e.g. a logical IF function)? I am currently using XP Office with
>Excel 2002.
Stan Brown - 10 Feb 2008 12:30 GMT
Sat, 9 Feb 2008 16:19:00 -0800 from  <=?Utf-8?B?UGF0cmljayAoR1ZDKQ==?
= <Patrick (GVC)@discussions.microsoft.com>>:
> Does anyone know a method of calling/running a macro from within a cell
> function (e.g. a logical IF function)? I am currently using XP Office with
> Excel 2002.

Make it a user-defined function. As far as I know, a function can
contain any code that you could put into a macro.

Signature

Stan Brown, Oak Road Systems, Tompkins County, New York, USA
                                  http://OakRoadSystems.com
A: Maybe because some people are too annoyed by top posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.