Sub Data_Start_End_Years()
Dim rngStart As Range, rngEnd As Range
Dim lStart As Long, lEnd As Long
Do
lStart = Application.InputBox("Enter the start year. ", "Start Year", Type:=1)
If lStart = 0 Then Exit Sub 'User canceled
lEnd = Application.InputBox("Enter the end year. ", "End Year", Type:=1)
If lEnd = 0 Then Exit Sub 'User canceled
If lEnd < lStart Then MsgBox "The End year must be greater than the Start year. ", vbExclamation, "Invalid Year Entries"
Loop While lEnd < lStart
Set rngStart = Range("O2:AR2").Find(lStart, , , xlWhole, , xlNext)
Set rngEnd = Range("O2:AR2").Find(lEnd, , , xlWhole, , xlNext)
If rngStart Is Nothing Then
MsgBox "Cannot find the start year column. ", vbExclamation, "Start Year Not Found"
Exit Sub
ElseIf rngEnd Is Nothing Then
MsgBox "Cannot find the end year column. ", vbExclamation, "End Year Not Found"
Exit Sub
End If
Application.ScreenUpdating = False
If rngEnd.Column < 44 Then Columns(rngEnd.Column + 1).Resize(, 44 - rngEnd.Column + 1).Delete
If rngStart.Column > 15 Then Columns(15).Resize(, rngStart.Column - 15).Delete
Application.ScreenUpdating = True
End Sub
Bookmarks