VBA Ending Sub Routine Question

Carl Clements

Board Regular
Joined
Jun 13, 2008
Messages
95
Hi,

Can anybody help me End my Sub routine if a condition is not met, or continue through the rest of the code if it is?

The code is below and I want the routine to stop after the red code if the condition in blue is NOT met. If it is met, i want the macro to continue through the code to the end. At the moment, the code is continuing to the end regardless.

Sub TEMPLATE_1st_Auth()
If ActiveSheet.Name = "NAVSUMM Checks" Then
Call NAVcheck

End If

'If differences on NAVcheck exist, display pop-up box. If not, proceed with second authorisation

[X1].Select
If WorksheetFunction.Sum(ActiveCell.EntireColumn) = 0 Then

Else

Call ZUCSD_NAVSUMM_Diff_Message

Sheets("NAVSUMM Checks").Select


'Lock all cells
Cells.Select
Selection.Locked = True
Selection.FormulaHidden = False
Range("A1").Select

'For tracking of 'Report Overview' spreadsheet.
MySheetNumber = ActiveSheet.Index
AuthoriseStage = """" & "1st Authorisation" & """"
Call ValuationDate
Call Find_Template
'Get user name, make Uppercase and store in cell BA1
MyNum = Environ("UserName")
MyNum = UCase(MyNum)

Range("BA1").Value = MyNum

Range("A1").Select


'Adjust size of spreadsheet to 85% for consistent sizes of text boxes

ActiveWindow.Zoom = 85
Range("A1").Select

'Create text box - numbers mean distance from left, height from top of sheet, width of box, length of box, height of box
Dim Sh As Shape

Set Sh = ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 290, 50, 210, 25)
'Name text box
Sh.Name = "TEMPLATEFirstAuth"

'Find out what text is in the text box and store it as variable 'First'
First = ActiveSheet.Shapes("TEMPLATEFirstAuth").TextFrame.Characters.Text

With ActiveSheet.Shapes("TEMPLATEFirstAuth")
.TextFrame.Characters.Text = "First authorised: " & MyNum & " " & Date & " " & Format(Time, "HH:MM")
.Fill.ForeColor.SchemeColor = 23
End With

ActiveSheet.Shapes("TEMPLATEFirstAuth").Select
With Selection.Characters(Start:=1, Length:=90).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Selection.HorizontalAlignment = xlCenter
Selection.VerticalAlignment = xlCenter
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 44
Selection.ShapeRange.Fill.Transparency = 0#
Selection.ShapeRange.Line.Weight = 0.75
Selection.ShapeRange.Line.DashStyle = msoLineSolid
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.Transparency = 0#
Selection.ShapeRange.Line.Visible = msoTrue
Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

'Select format properties of box
With Selection
.Placement = xlFreeFloating
.PrintObject = True
End With

'Select worksheet and protect
ActiveSheet.protect Password:="ldvt", UserInterfaceOnly:=True


'Make relevant buttons visible
ActiveSheet.Shapes("Button 2").Visible = False
ActiveSheet.Shapes("Button 3").Visible = True
ActiveSheet.Shapes("Button 4").Visible = True
ActiveSheet.Shapes("Button 5").Visible = False

End If


End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Replace the code in blue with the following:

Code:
If WorksheetFunction.Sum(ActiveCell.EntireColumn) <> 0 Then Exit Sub

Also, you don't need to select sheets or cells to perform actions on them, and a lot of the code which formats cells looks like it was generated by the macro recorder, and could be removed to speed up your code.
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,572
Members
452,927
Latest member
whitfieldcraig

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