+ Reply to Thread
Results 1 to 7 of 7

Having trouble using a nested IF with VBA msgbox

  1. #1
    Registered User
    Join Date
    07-09-2014
    Location
    Naperville, IL
    MS-Off Ver
    office 2013
    Posts
    29

    Having trouble using a nested IF with VBA msgbox

    Hello,

    I am looking to have my VBA code trigger a message box upon opening the file which asks the user if they'd like to clear certain cells. I want the "Yes" on the first question to trigger another message box asking them if they are sure they want to go through with it. I need the "Yes" on the second message box to clear the cells. Thank you for the help, here is my code:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Having trouble using a nested IF with VBA msgbox

    Your code works just fine

  3. #3
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Having trouble using a nested IF with VBA msgbox

    Worked fine for me as well.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  4. #4
    Registered User
    Join Date
    07-09-2014
    Location
    Naperville, IL
    MS-Off Ver
    office 2013
    Posts
    29

    Re: Having trouble using a nested IF with VBA msgbox

    I shortened the event trigger just to make it simpler, but turns out that was the issue. Here is my actual code with the actual ranges that need to be cleared. This is giving me the error of "Application-defined or object-defined error".

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Having trouble using a nested IF with VBA msgbox

    If you want to specify each range like that you are going to need to use the Union property. Very tedious but it will work
    Please Login or Register  to view this content.

    Another option would be to incorporate a looping structure if there is consistency amongst your columns. I have given you an example, up to you to make sure it works for your data set
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-09-2014
    Location
    Naperville, IL
    MS-Off Ver
    office 2013
    Posts
    29

    Re: Having trouble using a nested IF with VBA msgbox

    Thank you very much. I used the first one since there isn't much consistency in the worksheet. Can you only loop if there aren't consistent columns or is there a way around that? Thanks again.

  7. #7
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Having trouble using a nested IF with VBA msgbox

    You can loop through each column but there needs to be a mechanism in place to tell the code which columns to apply the code to. This can be done many ways, but at this point it might be best just to work with the first option I showed you. In retrospect, we could have created an array of each column that you need the code applied then looped through the array. Next time.

+ 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] Trouble with Nested If
    By shaught7 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 07-25-2014, 02:26 PM
  2. [SOLVED] Having trouble with msgbox vbYesNo
    By Tayjayt in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-25-2013, 12:55 AM
  3. [SOLVED] MsgBox Nested Ifs
    By thesonofdarwin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-28-2013, 10:54 PM
  4. Having trouble with nested if commands
    By pmilligan1979 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-11-2012, 02:12 PM
  5. Trouble with nested IF formula
    By TheRobsterUK in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-04-2005, 10: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