Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default 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 -


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default 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 -


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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 -


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validate same month and same year salgud Excel Programming 2 July 13th 09 04:05 PM
convert day of year to numeric value format year+day in 4 digits Kaaren Excel Worksheet Functions 3 February 7th 09 08:37 PM
How do I crate a function for week of year + year in same cell. patty ann Excel Worksheet Functions 1 March 16th 08 06:34 PM
Combination Graph with current year and prior year sales JanW Charts and Charting in Excel 2 April 5th 07 09:20 PM
trying to get day/month/year froamt while user enters year only RADIOOZ New Users to Excel 3 June 7th 06 05:30 AM


All times are GMT +1. The time now is 05:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"