+ Reply to Thread
Results 1 to 12 of 12

VBA IF nested with MSGBOX

  1. #1
    Registered User
    Join Date
    08-23-2015
    Location
    Texas, USA
    MS-Off Ver
    Ms Office Pro 2019
    Posts
    26

    VBA IF nested with MSGBOX

    I am trying to get this code to work with no success...
    Heres my code:

    Please Login or Register  to view this content.
    What i am trying to accomplish is this,
    If cell I28 has a value then bypass the message box and run all the "call" codes.
    but if cell I28 does not have a value then i want the message box to pop up asking if i want to continue running all the "call" code or not.
    if i click cancel then stop the code from running anymore.
    If I click "Ok" then go ahead and run all the "call" code.
    I have tried everything i know but just cant get it work correctly.
    Currently as i have it, the Message box part works, it cancels when i click on "cancel" and runs when i click on "OK".
    but if cell I28 has a value, nothing happens when it should just bypass the message box part and run the code.
    I appreciate the help in advance!!
    Last edited by JDLuke; 10-21-2023 at 11:14 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: VBA IF nested with MSGBOX

    Please Login or Register  to view this content.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    08-23-2015
    Location
    Texas, USA
    MS-Off Ver
    Ms Office Pro 2019
    Posts
    26

    Re: VBA IF nested with MSGBOX

    THANK YOU! THANK YOU!
    works exactly as i need it to!
    I was so close.
    I see the differant placement of the "End If" and can see where that would make a differance.
    But, does it make a differance that the "IF" line is after the "DIM" line?
    Was that one of the problems i had with it?
    I am wanting to learn...
    But none the less...THANK YOU!!

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: VBA IF nested with MSGBOX

    But, does it make a difference that the "IF" line is after the "DIM" line?
    No. It just makes it easier to read when all variables are declared at the top. The VB interpreter has to parse the entire code looking for variable declarations and grabbing chunks of memory for each one before it executes any code.
    Last edited by protonLeah; 10-22-2023 at 02:07 PM.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA IF nested with MSGBOX


    By the way it can be directly achieved without using such useless variable …

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: VBA IF nested with MSGBOX

    ..........

  7. #7
    Registered User
    Join Date
    08-23-2015
    Location
    Texas, USA
    MS-Off Ver
    Ms Office Pro 2019
    Posts
    26

    Re: VBA IF nested with MSGBOX

    Quote Originally Posted by Marc L View Post

    By the way it can be directly achieved without using such useless variable …
    Marc, Would you care to show me the code?

  8. #8
    Registered User
    Join Date
    08-23-2015
    Location
    Texas, USA
    MS-Off Ver
    Ms Office Pro 2019
    Posts
    26

    Re: VBA IF nested with MSGBOX

    Quote Originally Posted by protonLeah View Post
    No. It just makes it easier to read when all variables are declared at the top. The VB interpreter has to parse the entire code looking for variable declarations and grabbing chunks of memory for each one before it executes any code.
    Ahh.. okay. I see what you mean.
    Thanks!!

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this ...


    Quote Originally Posted by JDLuke View Post
    Marc, Would you care to show me the code?
    So removing the useless the VBA procedure revamped :

    PHP Code: 
    Sub SavePrintNewWB()
        If [
    I28=""Then If MsgBox("Continue Without CK#?"257"Check Number Valadation") = 2 Then Exit Sub
        CopyDataToLedger
        EntryNumber
        SaveWB
        MakeFolderAndSave
        PrintSheet
        OpenNewTimeSheet
        ClearTimeSheet
        ExitWithoutPrompt
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 10-25-2023 at 02:57 PM.

  10. #10
    Registered User
    Join Date
    08-23-2015
    Location
    Texas, USA
    MS-Off Ver
    Ms Office Pro 2019
    Posts
    26

    Re: Try this ...

    Quote Originally Posted by Marc L View Post

    So removing the useless the VBA procedure revamped :

    PHP Code: 
    Sub SavePrintNewWB()
        If [
    I28=""Then If MsgBox("Continue Without CK#?"257"Check Number Valadation") = 2 Then Exit Sub
        CopyDataToLedger
        EntryNumber
        SaveWB
        MakeFolderAndSave
        PrintSheet
        OpenNewTimeSheet
        ClearTimeSheet
        ExitWithoutPrompt
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Thanks Marc!
    I'll give this a try..
    Looks like it should work....
    What does the "257" in the MsgBox mean?

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Try this ...


    Quote Originally Posted by JDLuke View Post
    What does the "257" in the MsgBox mean?
    That means vbOKCancel + vbDefaultButton2

  12. #12
    Registered User
    Join Date
    08-23-2015
    Location
    Texas, USA
    MS-Off Ver
    Ms Office Pro 2019
    Posts
    26

    Re: Try this ...

    Quote Originally Posted by Marc L View Post

    That means vbOKCancel + vbDefaultButton2
    Oh cool! Ok... i didnt know there was a differant way of expressing the "syntax", so to speak, for msgbox commands.

+ 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. Cannot get Nested ifs for a search after msgbox yes answer to work
    By lOYvEpi6M87nEoIF0ul8 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-25-2021, 12:52 AM
  2. [SOLVED] MsgBox containing Data along with password to close the MsgBox
    By quirkybox in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-21-2020, 05:44 AM
  3. Macro to capture MsgBox prompt to a string variable but ignore the MsgBox
    By BuglerDobbs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-07-2015, 10:56 AM
  4. [SOLVED] Having trouble using a nested IF with VBA msgbox
    By msantucci in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-07-2015, 03:19 PM
  5. [SOLVED] Problem with VBA Editor uses lower case on some lines (ex. msgbox instead of MsgBox)
    By stubbsj in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-14-2013, 06:59 PM
  6. [SOLVED] MsgBox Nested Ifs
    By thesonofdarwin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-28-2013, 10:54 PM
  7. MsgBox-center the message on a msgbox
    By CobraLAD in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-11-2007, 06:48 AM

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