+ Reply to Thread
Results 1 to 3 of 3

Nesting Conditions and using Yes/No MsgBoxes to execute a code

Hybrid View

  1. #1
    Registered User
    Join Date
    07-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    88

    Nesting Conditions and using Yes/No MsgBoxes to execute a code

    Hi all,

    I have a workbook that I run each day for a simple data process. One page in the workbook ("Integrity") contains a series of 2 checks on different conditions within the data. Ideally, if one of these checks is breached/tripped, I would like the user to know about it, so he/she can go and check the data and make sure that the exception is okay.

    My code is below. Potentially, there are 2 checks that can be tripped. If none of them are tripped, the fields in the workbook will simply read "OK". If the condition is breached, then the respective field will display "CHECK". If a field displays "CHECK" I want the user to see a message box that will describe the problem and ask if he/she wishes to continue. If they click "No", the macro will terminate. Then they can go and look at the data and see if there's a problem. If they click "Yes", then I would like for the routine to continue running. If neither check is tripped, or the user clicks "yes" to continue past one or more MsgBoxes, then the routine should keep running.

    Does anyone know how to nest these If, Then statements - combined with MsgBoxes that have a yes or no output? In summary, if field C4 or C5 contains "CHECK", then a message box should pop up. If the box pops up, it should give an option to continue the macro or quit the macro. If neither C4 nor C5 contains "CHECK", then no box should be displayed and the macro should just run through.

    Any and all help is appreciated as I've tried several things and had no luck.

    Thanks!

    Sub RunProcess()
    
    
    
    Dim OutPut1 As Integer
    Dim OutPut2 As Integer
    
    
    
    
    If Sheets(Sheet5.Name).Range("C4").Value = "CHECK" Then
    OutPut1 = MsgBox("Please check that all data is present. Do you want to continue?", vbQuestion + vbYesNo, "Integrity Breach: Data Count")
        If OutPut1 = 7 Then
        Exit Sub
    
        Else
    
    If Sheets(Sheet5.Name).Range("C6").Value = "CHECK" Then
    OutPut2 = MsgBox("Price integrity breach detected - ensure all underlying fields have prices. Do you want to continue?", vbQuestion + vbYesNo, "Integrity Breach: Price Count")
    If OutPut2 = 7 Then
    Exit Sub
            
            
    Else
    
    Call DailyRoutine
    
    
    End If
    End If
    End If
    End If
    
    
    
    
    End Sub

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

    Re: Nesting Conditions and using Yes/No MsgBoxes to execute a code

    See note on sheet name.

    Sub RunProcess()
    Dim ws As Worksheet:    Set ws = Sheets("Sheet1") 'you probably don't want to use Sheet5.Name.  Sheet5 is an index. Use the actual sheet name instead and surround in quotes.
    Dim msg
    Dim rCell As Range
    
    For Each rCell In ws.Range("C4:C5")
        If UCase(rCell) = "CHECK" Then
            msg = MsgBox("Please check that all data is present. Do you want to continue?", vbQuestion + vbYesNo, "Integrity Breach: Data Count")
                If msg = vbNo Then
                    Exit Sub
                End If
        End If
    Next rCell
    
    MsgBox ("Subroutine Complete")
    
    End Sub

  3. #3
    Registered User
    Join Date
    07-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Nesting Conditions and using Yes/No MsgBoxes to execute a code

    thanks, this helped me solve my problem. I now understand how to loop through the criteria range. Thanks for the comment about Sheet5.Name being an index, as well

+ 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. Suppressing msgboxes appearing during loop
    By msixdatateam in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-24-2014, 01:13 PM
  2. Nesting IF Formula with multiple conditions
    By coloradolime in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 03-05-2014, 05:38 PM
  3. Need to suppress MsgBoxes
    By bconner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-20-2009, 02:12 PM
  4. Exceedeing the 7 conditions in a nesting fomula
    By Nick in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2006, 01:55 PM
  5. [SOLVED] Nesting more than 7 conditions?
    By Gina in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-08-2006, 09:45 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