Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Change event - checking dates

I have a spreadsheet where the user enters dates into cells within a
range.

I need to check that the date is within a 2 year before and after the
current time.

I have worked out the following code to do the job. It works fine
if I knock out the: Target = Range("matrix")

I don't want the code to work on cells outside the range("matrix").
I also am trying to get the code to 'see' an empty cell and not
colour it in if the cell is empty, but previously contained an out of
range (2 year) date.

Why does the code not work when the: Target = Range("matrix") is
made available?

Thanks,

Ian,




Private Sub Worksheet_Change(ByVal Target As Range)

over730days = Now() + 730
under730days = Now() - 730

Target = Range("matrix")

For Each cell In Target
If ((cell.Value over730days) Or (cell.Value < under730days)) Then
cell.Interior.ColorIndex = 8

Next cell

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Change event - checking dates

Maybe two options both of which will mean this event will run every time
any change is made on the sheet:

Private Sub Worksheet_Change(ByVal Target As Range)
over730days = Now() + 730
under730days = Now() - 730
set Target = Range("matrix")
For Each cell In Target
If ((cell.Value over730days) Or (cell.Value < under730days)) Then
cell.Interior.ColorIndex = 8
Next cell
End Sub

or:

Private Sub Worksheet_Change(ByVal Target As Range)
over730days = Now() + 730
under730days = Now() - 730
For Each cell In range("Matrix")
If ((cell.Value over730days) Or (cell.Value < under730days)) Then
cell.Interior.ColorIndex = 8
Next cell
End Sub

But you would probably be a whole lot better off doing this with
conditional formatting which would take away the need for any vba.

Hope this helps
Rowan

Ian wrote:
I have a spreadsheet where the user enters dates into cells within a
range.

I need to check that the date is within a 2 year before and after the
current time.

I have worked out the following code to do the job. It works fine
if I knock out the: Target = Range("matrix")

I don't want the code to work on cells outside the range("matrix").
I also am trying to get the code to 'see' an empty cell and not
colour it in if the cell is empty, but previously contained an out of
range (2 year) date.

Why does the code not work when the: Target = Range("matrix") is
made available?

Thanks,

Ian,




Private Sub Worksheet_Change(ByVal Target As Range)

over730days = Now() + 730
under730days = Now() - 730

Target = Range("matrix")

For Each cell In Target
If ((cell.Value over730days) Or (cell.Value < under730days)) Then
cell.Interior.ColorIndex = 8

Next cell

End Sub

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
Sumproduct checking between two dates bikergsx Excel Worksheet Functions 2 May 26th 06 10:21 AM
Checking difference between the dates mac_see[_3_] Excel Programming 2 April 7th 05 09:17 PM
Change event and calculate event Antje Excel Programming 1 March 29th 05 09:03 PM
Checking for invalid dates Matt Pinto Excel Programming 3 November 28th 03 12:11 PM
change event/after update event?? scrabtree23[_2_] Excel Programming 1 October 20th 03 07:09 PM


All times are GMT +1. The time now is 10:44 AM.

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

About Us

"It's about Microsoft Excel"