Sub Exiting Without Moving Through Completely

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
Office Version
  1. 365
Platform
  1. Windows
For some reason, the code below isn't moving on to the Else statement when the value of R26 isn't > 0. Can someone help me understand where I went wrong in my code please?
Code:
Sub Assign_MD1()
Application.ScreenUpdating = False
Dim mTP, mSumm, mMD1 As Worksheet
Dim Response As VbMsgBoxResult
Set mTP = ThisWorkbook.Sheets("Total_Population")
Set mSumm = ThisWorkbook.Sheets("Summaries")
Set mMD1 = ThisWorkbook.Sheets("MD1")
If mTP.FilterMode = True Then mTP.ShowAllData
'If Len(frm_IntakeHome.cobo_ImportType.Value) = 0 Then
'    MsgBox "Please enter the import type you are processing."
'    If Response = vbOK Then frm_IntakeHome.cobo_ImportType.SetFocus
'    Cancel = True
'    Exit Sub
'Else
If mSumm.Range("R26").Value > 0 Then
    Response = MsgBox("Please review the records that show as past SLA, and make any necessary corrections.", vbOKCancel)
    If Response = vbOK Then
        With mTP
            On Error Resume Next
            .UsedRange.AutoFilter Field:=8, Criteria1:="<" & Date
            .UsedRange.AutoFilter Field:=13, Criteria1:="Y"
        End With
    mTP.Activate
    'Exit Sub
Else
    If mTP.FilterMode = True Then mTP.ShowAllData
    SortAscending mTP, "J1", "M1"
    With mTP
        On Error Resume Next
        .UsedRange.AutoFilter Field:=10, Critiera1:=""
        .UsedRange.AutoFilter Field:=13, Critiera1:="Y"
    End With
    End If
End If
    
mTP.Activate
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Get rid of this
Code:
On Error Resume Next
both times it occurs & see what happens.
 
Upvote 0
Ok, I did that, but there was no change in the result.

**Edit** I'm not sure if it matters (I don't think that it would), but just in case...the value of R26 is actually a formula that is summing 4 other fields.
 
Last edited:
Upvote 0
Hi,

I think your first nested If statement is missing an End IF, so the Else is being applied to it?

Code:
If mSumm.Range("R26").Value > 0 Then
    Response = MsgBox("Please review the records that show as past SLA, and make any necessary corrections.", vbOKCancel)
    If Response = vbOK Then
        With mTP
            On Error Resume Next
            .UsedRange.AutoFilter Field:=8, Criteria1:="<" & Date
            .UsedRange.AutoFilter Field:=13, Criteria1:="Y"
        End With
    mTP.Activate
    'Exit Sub
[COLOR="#FF0000"]    End IF[/COLOR]
Else

Insert line in Red above & try.

Hope this helps,

Eric
 
Upvote 0
Ok, what is the Value in R26, when it doesn't work?
 
Upvote 0
Good spot Eric.

The End If is in the wrong place it should be
Code:
If mSumm.Range("R26").Value > 0 Then
    Response = MsgBox("Please review the records that show as past SLA, and make any necessary corrections.", vbOKCancel)
    If Response = vbOK Then
        With mTP
            On Error Resume Next
            .UsedRange.AutoFilter Field:=8, Criteria1:="<" & Date
            .UsedRange.AutoFilter Field:=13, Criteria1:="Y"
        End With
    mTP.Activate
    'Exit Sub
    End If
Else
    If mTP.FilterMode = True Then mTP.ShowAllData
    SortAscending mTP, "J1", "M1"
    With mTP
        On Error Resume Next
        .UsedRange.AutoFilter Field:=10, Critiera1:=""
        .UsedRange.AutoFilter Field:=13, Critiera1:="Y"
    End With
End If
 
Upvote 0
Thank you @Eric Golf! After you pointed that out, I noticed that it was odd that the code was skipping to the End If way at the bottom. Much appreciated!
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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