Q:

VBA how to: Text box is greater than current year?

Hi everyone and thanks for having a look at my problem. 
I want to create a button in my User form where it will check if the year entered in TextBox_Year is between 2013 and the current year (has to be variable so it changes as time goes). 
I've been searching the web for a solution to my problem, but nothing seems to work. 
Underneath is my current code, and the problem is in bold. I have also tried to enter Year(date) and year(today()) with no luck.
The cell CurrentYear is a named cell in my workbook containing =Year(today()) and displays 2014 (which is the value I want)
Again thanks for all help!
Private Sub CommandButton_OK_Click()    
If UserForm1.TextBox_Year.Value <= "2012" Then
MsgBox "Please enter a year between 2013 and the year you are in."    
    ElseIf UserForm1.TextBox_Year.Value > **Range("CurrentYear").Value** Then
MsgBox "Please enter a year between 2013 and the year you are in." 
Else:
    UserForm1.Hide  
End If
End Sub

A:

Try this code:
Private Sub CommandButton_OK_Click()
    Dim textYear As Integer

    On Error GoTo errHandler
    textYear = CInt(UserForm1.TextBox_Year.Value)
    If textYear <= 2012 Then
        MsgBox "Please enter a year between 2013 and the year you are in."
    ElseIf textYear > Range("CurrentYear").Value Then
        MsgBox "Please enter a year between 2013 and the year you are in."
    Else
        UserForm1.Hide
    End If
    Exit Sub
errHandler:
    MsgBox Err.Description
End Sub

