+ Reply to Thread
Results 1 to 7 of 7

Macro to Run if the 'If' is true else custom message to be displayed.

  1. #1
    Registered User
    Join Date
    08-13-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    87

    Macro to Run if the 'If' is true else custom message to be displayed.

    Hello,

    I have the code that is ready and working, now I want to add one condition at the start. If the condition is true then macro should run else message box should pop up. I thought of something like this


    Please Login or Register  to view this content.

    But I get an 'Complie Error: Else Without If', can some one please point out what I am doing wrong here.


    Thanks,
    Aadesh Gandhi.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro to Run if the 'If' is true else custom message to be displayed.

    Hi, Aadesh Gandhi.,

    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    08-13-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Macro to Run if the 'If' is true else custom message to be displayed.

    Quote Originally Posted by HaHoBe View Post
    Hi, Aadesh Gandhi.,

    Please Login or Register  to view this content.
    Ciao,
    Holger
    Hello Holger,
    Your code looks similar to mine, so was this just a formatting thing?


    R/
    Aadesh

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro to Run if the 'If' is true else custom message to be displayed.

    Hi, Aadesh Gandhi.,

    close but no cigar...

    Your If-statement ends right at the end of the first line as you wrote the Then part right behind the Then. Doing it that way leaves you just with the TRUE condition, no Else-statement is possible for this one-liner.

    Mine was structured like this:
    Please Login or Register  to view this content.
    And there´s no comment from the compiler about my code, is it?

    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    08-13-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Macro to Run if the 'If' is true else custom message to be displayed.

    Quote Originally Posted by HaHoBe View Post
    Hi, Aadesh Gandhi.,

    close but no cigar...

    Your If-statement ends right at the end of the first line as you wrote the Then part right behind the Then. Doing it that way leaves you just with the TRUE condition, no Else-statement is possible for this one-liner.

    Mine was structured like this:
    Please Login or Register  to view this content.
    And there´s no comment from the compiler about my code, is it?

    Ciao,
    Holger
    Nope no issues with your code. It does work great! I am still learning things so want to understand if my logic was flawed or my formatting.

    Thanks for your help!

    Aadesh

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro to Run if the 'If' is true else custom message to be displayed.

    Hi, Aadesh,

    you´re welcome. Please do not quote whole posts - maybe have a look at Rule 12 for more information.

    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    08-13-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Macro to Run if the 'If' is true else custom message to be displayed.

    Quote Originally Posted by HaHoBe View Post
    Please do not quote whole posts
    Holger,
    Will follow it moving forward.


    Thanks,
    Aadesh

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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