Compile Error Block If End If

bloodmilksky

Board Regular
Joined
Feb 3, 2016
Messages
202
Hi Guys,

This is my first real attempt at writing some code. I think I have got everything right but keeps on coming up with a Compile Error Block If End IF.

Can anyone help ?

Code:
Dim daysremaining As Integer, daystaken As Integer, result As String, myValue As Variantdaystaken = Range("B13").Value
daysremaining = Range("D14").Value


If daysremaining <= 1 Then
    Msg = " You Do Not Have Enough Holiday! Would You Like To Continue ? " & Application.UserName
    Ans = MsgBox(Msg, vbYesNo)
    If Ans = vbNo Then
                Application.DisplayAlerts = False
                ThisWorkbook.Save
                Application.DisplayAlerts = True
                Application.Quit
                End If
    If Ans = vbYes Then
                    Sheets("Request Form").Select
                    Range("Employee3").ClearContents
                    Range("DateRequest").ClearContents
                    Range("Employee3") = Application.UserName
                    End If
If daystaken >= 25 Then
    Msg = " You Do Not Have Enough Holiday! Would You Like To Continue ? " & Application.UserName
    Ans = MsgBox(Msg, vbYesNo)
    If Ans = vbNo Then
                Application.DisplayAlerts = False
                ThisWorkbook.Save
                Application.DisplayAlerts = True
                Application.Quit
                End If
    If Ans = vbYes Then
                    Sheets("Request Form").Select
                    Range("Employee3").ClearContents
                    Range("DateRequest").ClearContents
                    Range("Employee3") = Application.UserName
Else


NewBookingCheck.NewBookingCheck
End If


End If
End Sub

MAny thanks

Jamie
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Code:
Dim daysremaining As Integer, daystaken As Integer, result As String, myValue As Variantdaystaken = Range("B13").Value
daysremaining = Range("D14").Value


If daysremaining <= 1 Then
    Msg = " You Do Not Have Enough Holiday! Would You Like To Continue ? " & Application.UserName
    Ans = MsgBox(Msg, vbYesNo)
    If Ans = vbNo Then
                Application.DisplayAlerts = False
                ThisWorkbook.Save
                Application.DisplayAlerts = True
                Application.Quit
                End If
    If Ans = vbYes Then
                    Sheets("Request Form").Select
                    Range("Employee3").ClearContents
                    Range("DateRequest").ClearContents
                    Range("Employee3") = Application.UserName
                    End If
[COLOR=#FF0000][B]End If
[/B][/COLOR][COLOR=#FF0000][/COLOR]If daystaken >= 25 Then
    Msg = " You Do Not Have Enough Holiday! Would You Like To Continue ? " & Application.UserName
    Ans = MsgBox(Msg, vbYesNo)
    If Ans = vbNo Then
                Application.DisplayAlerts = False
                ThisWorkbook.Save
                Application.DisplayAlerts = True
                Application.Quit
                End If
    If Ans = vbYes Then
                    Sheets("Request Form").Select
                    Range("Employee3").ClearContents
                    Range("DateRequest").ClearContents
                    Range("Employee3") = Application.UserName
Else


NewBookingCheck.NewBookingCheck
End If


End If
End Sub
 
Upvote 0
Thank you I have made the adjustment but its not running the last bit of code?

Code:
[COLOR=#333333]Else[/COLOR]

NewBookingCheck.NewBookingCheck
End If


End If [COLOR=#333333]End Sub[/COLOR]
 
Upvote 0
It compiles without a problem for me. Note that "End Sub" shouldn't follow "End If", it should be on a separate line.
 
Last edited:
Upvote 0
@bloodmilksky, assuming that Neil's post solved your issue then just a suggestion but if you install the code indenter in the link below it will indent the code in such a way that things like Ifs and End If's end up lining up making it much easier to spot errors like the missing End If.


Office Automation Ltd. - Smart Indenter
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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