How To Do An If Then Statement :: Message Box Otherwise Execute Code

drmingle

Board Regular
Joined
Oct 5, 2009
Messages
229
I would like to run the below code only when there is no "x"'s in the following ranges:

ActiveSheet.Range("C16:C633")


Code:
Sub msgReset()
    Dim iRet As Integer
    Dim strPrompt As String
    Dim strTitle As String
    Dim num As Integer
    Dim var2 As String
    
    var2 = "x"
    
    Sheets("Pricing").Select
  
    num = Application.CountIf(ActiveSheet.Range("C16:C633"), var2)
    ' Prompt
    strPrompt = num & " 'excluded' services will not be reset, is this OK?"
 
    ' Dialog's Title
    strTitle = ".:: Reset Increase/Decrease to 100% ::."
 
    'Display MessageBox
    iRet = MsgBox(strPrompt, vbYesNo, strTitle)
 
    ' Check pressed button
    If iRet = vbNo Then
        Exit Sub
    Else
        Call Inclusion
    End If

End Sub

otherwise
Call Inclusion
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Do you mean you want to call Inclusion if there are no 'x' in the C16:C33?
 
Upvote 0
This ended up doing the trick...

Code:
Sub msgReset()
    Dim iRet As Integer
    Dim strPrompt As String
    Dim strTitle As String
    Dim num As Integer
    Dim var2 As String
    
    var2 = "x"
    
    Sheets("Pricing").Select
  
    num = Application.CountIf(ActiveSheet.Range("C16:C633"), var2)
    
    If num = 0 Then
        Call Inclusion
    End If
    
    If num > 0 Then
    
    ' Prompt
    strPrompt = num & " 'excluded' services will not be reset, is this OK?"
 
    ' Dialog's Title
    strTitle = ".:: Reset Increase/Decrease to 100% ::."
 
    'Display MessageBox
    iRet = MsgBox(strPrompt, vbYesNo, strTitle)
 
    ' Check pressed button
    If iRet = vbNo Then
        Exit Sub
    Else
        Call Inclusion
    End If
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,518
Messages
6,119,988
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top