+ Reply to Thread
Results 1 to 4 of 4

How do I "call" a macro as part of an 'if' statement

Hybrid View

  1. #1
    Registered User
    Join Date
    10-10-2013
    Location
    Edmonton, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    29

    How do I "call" a macro as part of an 'if' statement

    I am trying to call a macro as part of an 'if' statement as follows:

    =IF(Summary!C5="No",call.macro3,"No AP Required")

    I am sure it is a syntax error? What would be the proper wording for this?

    The more I use this site the more knowledgeable I become.

    Thanks for the help....


    Dragman

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: How do I "call" a macro as part of an 'if' statement

    You cannot call a macro from a cell. You can convert it to a function and call that, but whether it will work depends on what the routine does. There are strict rules about what functions called from cells can do.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    10-10-2013
    Location
    Edmonton, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    29

    Re: How do I "call" a macro as part of an 'if' statement

    So how do I convert it to a function? I want it to delete rows in one worksheet based upon the value of a cell in another worksheet.

  4. #4
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    818

    Re: How do I "call" a macro as part of an 'if' statement

    How about below:

    Sub CallMacro3()
    Dim ws As Worksheet
    Set ws = Worksheets("Summary")
    If ws.Range("C5").Value = "No" Then
    Call Macro3
    Else
    ws.Range("C5").Value = "No AP Required"
    End If
    End Sub
    
    Sub Macro3()
    MsgBox "Bingo"  '''enter your code here
    End Sub
    Regards,
    tt3

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Use of calculated field in "WHERE" part of SQL statement?
    By studiosa in forum Access Tables & Databases
    Replies: 2
    Last Post: 09-06-2013, 01:00 PM
  2. [SOLVED] Can't call Sub from within "IF" statement in cell in spreadsheet.
    By billmarshall in forum Excel General
    Replies: 9
    Last Post: 09-04-2012, 03:11 PM
  3. Replies: 3
    Last Post: 12-14-2006, 01:36 PM
  4. Call a sub statement in "Personal Macro Workbook" from "ThisWorkbo
    By QC Coug in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2005, 03:05 PM
  5. Replies: 3
    Last Post: 05-27-2005, 06:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1