+ Reply to Thread
Results 1 to 9 of 9

calling a macro in a IF statement

  1. #1
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    calling a macro in a IF statement

    I have tried to look online and not seems to make sense and unfortunately I don't know
    how to code in vba, so I am doing it the long way.

    What I would like to know can you call a macro to run within a If statement.

    The way I am thinking is something along the lines of,

    =if(q6>"",call clear (being the macro) etc etc
    One I have learnt over the last few months, " You are NEVER too old to learn ".
    Sometimes I forget to say " Thank You " for your assistance, so here I say " A BIG Thank You. "

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,008

    Re: calling a macro in a IF statement

    .
    Paste this in the sheet level module :

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: calling a macro in a IF statement

    Good afternoon logit.

    Thank you for that I wish to learn more about VBA so if you would within your code
    add a comment line as to just what each line is doing.

    I don't quite understand the ( If ME.range ) segment

    My macro is called "Clear"

    I will not need a message after the macro has run as it will be part of a bigger statement.

    Thank you.

  4. #4
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: calling a macro in a IF statement

    Hi all

    I have attached my "Peter" worksheet.

    I am going to write some excel if statements to that when a new number is entered in cell "D6" it starts a series of events the first is to run the clear macro first.

    ATM, However I am having troubles getting the macro to check and clear cells (H6,H13,J6,J13,L6,L13,Q6)

    Logit sent some code but it is not what I was expecting, I did ask for only one cell so that was my fault.

    So what I am after is when any digit is entered into Cells D6 or D13 that it first runs the clear macro, ( If possible ).

    Pete
    Attached Files Attached Files

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: calling a macro in a IF statement

    You have a clear button on the page - I would recommend that you use that, as that is what anyone filling out an interface like this would expect (it's usually called RESET). Trying to clear cells as someone starts typing into one of the fields is going to make the macro overly complex, I suspect. You need to employ the KISS principle.

    As for combining macros with IF statements, again, I wouldn't muddle functionality, personally, as it will get overly complex.

    A slightly more detailed explanation of what you are trying to do with this scenario would help.
    Last edited by AliGW; 07-18-2019 at 01:08 AM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  6. #6
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: calling a macro in a IF statement

    Good Morning Boss Lady of the forum. (Tongue in ckeek)

    I sort of figured I was trying to complicate thing, a bit more than a tad.

    Regards
    Pete

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: calling a macro in a IF statement

    I am glad you reached that conclusion yourself - progress!

    Boos Lady? Well, as far as I am aware, I am the only female mod here at this time.

  8. #8
    Forum Contributor Potholes's Avatar
    Join Date
    11-25-2011
    Location
    Brisbane
    MS-Off Ver
    Office 2021
    Posts
    774

    Re: calling a macro in a IF statement

    NOOOO BOSS Lady not BOOS Lady

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: calling a macro in a IF statement

    Not enough caffeine yet ... Early here!

+ 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. Execution Error when calling a sub statement
    By rakotonirinas in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-14-2019, 03:36 PM
  2. Error when calling a 'sheet macro' inside a workbook wide macro
    By Rhino_dance in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-09-2016, 03:46 PM
  3. [SOLVED] Define variable in macro than calling that macro inside another macro
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2015, 10:58 AM
  4. Calling Macro Based then bases result on True False Statement
    By jimrosser in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-25-2013, 04:39 PM
  5. [SOLVED] help with calling a function (B) and return control of program flow to the calling functio
    By john/nyc in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-26-2012, 11:06 AM
  6. calling cells that don't = 0, without if statement
    By lovethepirk in forum Excel General
    Replies: 3
    Last Post: 12-15-2009, 11:19 PM
  7. F4 key calling Macro instead of Macro's last statement.
    By astrodabu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2005, 12:13 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