VBA if statement to show msgbox and exit

I need to check if cell A2 is empty, and if so, show msgbox, show Sheet ("Detail") and exit all code.
The entire code if farther below.
I am getting error1.JPG

If A2 = "" Then
MsgBox = "No data meets minimum deficit weight."
Detail.Activate
End
End If

Open in new window




Sub FORMATREPORT()

Dim rng As Range
Dim LastRow As Long

If A2 = "" Then
MsgBox = "No data meets minimum deficit weight."
Detail.Activate
End
End If



Application.ScreenUpdating = False
        Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
        
    Range("A1:L1").Select
    Selection.Font.Bold = True
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
Set rng = Application.Intersect(ActiveSheet.UsedRange, Range("A:L"))
rng.SpecialCells(xlCellTypeVisible).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Columns("J:J").Select
    Selection.Style = "Comma"
    Selection.NumberFormat = "#,##0"
    Columns("K:K").Select
    Selection.Style = "Currency"
    Columns("L:L").Select
    Selection.Style = "Currency"
    Columns("I:I").Select
    Selection.Style = "Comma"
    Selection.NumberFormat = "_(* #,##0.0_);_(* (#,##0.0);_(* ""-""??_);_(@_)"
    Selection.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
    Columns("A:A").Select
    Selection.NumberFormat = "mm-dd-yyyy"

Columns("A:L").Select
Selection.EntireColumn.AutoFit

LastRow = Cells(Cells.Rows.Count, "J").End(xlUp).Row + 1
Range("K" & LastRow).Formula = "=SUM(K2:K" & LastRow - 1 & ")"
Range("L" & LastRow).Formula = "=SUM(L2:L" & LastRow - 1 & ")"





Application.ScreenUpdating = True
End Sub

Open in new window

Euro5Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
The message box call is done as:
MsgBox("Your message here")

Further details can be found here: https://msdn.microsoft.com/en-us/library/aa445082(v=vs.60).aspx
0
Russ SuterCommented:
You're treating MsgBox like a variable. It's not. The proper call would be

MsgBox("No data meets minimum deficit weight.")

Open in new window


See here for full usage documentation: https://msdn.microsoft.com/en-us/library/139z2azd%28v=vs.90%29.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Euro5Author Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.