ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Validate Year (https://www.excelbanter.com/excel-programming/432355-validate-year.html)

Ron[_6_]

Validate Year
 
Hello all,

I need code to confirm that the date in a cell is either in the
current year or the upcoming year and flag it if it's not. Assistance
appreciated. Thanks, Ron

Rick Rothstein

Validate Year
 
Something like this maybe...

CellYear = Year(Range("A1").Value)
If CellYear < Year(Now) Or CellYear Year(Now) + 1 Then
MsgBox "That is not a good date!"
End If

--
Rick (MVP - Excel)


"Ron" wrote in message
...
Hello all,

I need code to confirm that the date in a cell is either in the
current year or the upcoming year and flag it if it's not. Assistance
appreciated. Thanks, Ron



Ron[_6_]

Validate Year
 
Hi Rick, thanks for the assistance. I edited to the code below and
I'm getting a run time error "Object required".

Sub TestYearEffYr()
Dim cellyear As Range
Set cellyear = Year(Range("p4").Value)
If cellyear < Year(Now) Or cellyear Year(Now) + 1 Then
MsgBox "That is not a good date!"
End If
End Sub


On Aug 12, 4:21*pm, "Rick Rothstein"
wrote:
Something like this maybe...

CellYear = Year(Range("A1").Value)
If CellYear < Year(Now) Or CellYear Year(Now) + 1 Then
* MsgBox "That is not a good date!"
End If

--
Rick (MVP - Excel)

"Ron" wrote in message

...



Hello all,


I need code to confirm that the date in a cell is either in the
current year or the upcoming year and flag it if it's not. *Assistance
appreciated. *Thanks, Ron- Hide quoted text -


- Show quoted text -



Ron[_6_]

Validate Year
 
Hi Rick, got it. Seems to work I need a little more testing. Thanks
again for your assistance, Ron

Sub TestYearEffYr()
Dim cellyear As String
cellyear = Year(Range("p4").Value)
If cellyear < Year(Now) Or cellyear Year(Now) + 1 Then
MsgBox "That is not a good date!"
End If
End Sub

On Aug 12, 4:57*pm, Ron wrote:
Hi Rick, thanks for the assistance. *I edited to the code below and
I'm getting a run time error "Object required".

Sub TestYearEffYr()
Dim cellyear As Range
Set cellyear = Year(Range("p4").Value)
If cellyear < Year(Now) Or cellyear Year(Now) + 1 Then
* MsgBox "That is not a good date!"
End If
End Sub

On Aug 12, 4:21*pm, "Rick Rothstein"



wrote:
Something like this maybe...


CellYear = Year(Range("A1").Value)
If CellYear < Year(Now) Or CellYear Year(Now) + 1 Then
* MsgBox "That is not a good date!"
End If


--
Rick (MVP - Excel)


"Ron" wrote in message


...


Hello all,


I need code to confirm that the date in a cell is either in the
current year or the upcoming year and flag it if it's not. *Assistance
appreciated. *Thanks, Ron- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -



Rick Rothstein

Validate Year
 
Since you are storing the year in the cellyear variable, I would probably
Dim it as a Long instead of as a String.

--
Rick (MVP - Excel)


"Ron" wrote in message
...
Hi Rick, got it. Seems to work I need a little more testing. Thanks
again for your assistance, Ron

Sub TestYearEffYr()
Dim cellyear As String
cellyear = Year(Range("p4").Value)
If cellyear < Year(Now) Or cellyear Year(Now) + 1 Then
MsgBox "That is not a good date!"
End If
End Sub

On Aug 12, 4:57 pm, Ron wrote:
Hi Rick, thanks for the assistance. I edited to the code below and
I'm getting a run time error "Object required".

Sub TestYearEffYr()
Dim cellyear As Range
Set cellyear = Year(Range("p4").Value)
If cellyear < Year(Now) Or cellyear Year(Now) + 1 Then
MsgBox "That is not a good date!"
End If
End Sub

On Aug 12, 4:21 pm, "Rick Rothstein"



wrote:
Something like this maybe...


CellYear = Year(Range("A1").Value)
If CellYear < Year(Now) Or CellYear Year(Now) + 1 Then
MsgBox "That is not a good date!"
End If


--
Rick (MVP - Excel)


"Ron" wrote in message


...


Hello all,


I need code to confirm that the date in a cell is either in the
current year or the upcoming year and flag it if it's not. Assistance
appreciated. Thanks, Ron- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -




All times are GMT +1. The time now is 10:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com