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
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