PC Review


Reply
Thread Tools Rate Thread

Code to do edit checks when user moves out of a cell

 
 
Eric @ BP-EVV
Guest
Posts: n/a
 
      24th Apr 2008
I have a spreadsheet that the user inputs 4 dates (into 4 different cells)
where those dates are used in an SQL query against a database. Is there a way
to perform edit checks once the dates are input so as not to have the SQL
query execute until the dates are known to be valid ?

Base Period Start Date
Base Period End Date

Current Period Start Date
Current Period End Date

Obviously the start dates need to be before the respective end dates, but
also the Base Period needs to be prior to the Current Period. Also, no dates
can be blank, and none can be greater than yesterday.

Is there a way to execute a macro when each cell where these numbers are
input loses focus ... or am I better off with performing the total edit
checks once all 4 cells are filled in ?
 
Reply With Quote
 
 
 
 
Barb Reinhardt
Guest
Posts: n/a
 
      24th Apr 2008
I'd probably do it with a worksheet change event. SOmething like this

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRange As Range
Dim ValidDate As Boolean

If Target.Count > 1 Then Exit Sub
' The 4 ranges can be changed and represent the cells with dates
Set myRange = Union(Range("A1"), Range("B2"), Range("C3"), Range("D4"))

ValidDate = False

If Intersect(Target, myRange) Is Nothing Then Exit Sub

'Code Check for valid dates. When date is valid set ValidDate = True

If Not ValidDate Then
Target.Select
MsgBox ("Date is not a valid date")
End If

End Sub

You'll have to put the code together to determine if the date is valid.
--
HTH,
Barb Reinhardt



"Eric @ BP-EVV" wrote:

> I have a spreadsheet that the user inputs 4 dates (into 4 different cells)
> where those dates are used in an SQL query against a database. Is there a way
> to perform edit checks once the dates are input so as not to have the SQL
> query execute until the dates are known to be valid ?
>
> Base Period Start Date
> Base Period End Date
>
> Current Period Start Date
> Current Period End Date
>
> Obviously the start dates need to be before the respective end dates, but
> also the Base Period needs to be prior to the Current Period. Also, no dates
> can be blank, and none can be greater than yesterday.
>
> Is there a way to execute a macro when each cell where these numbers are
> input loses focus ... or am I better off with performing the total edit
> checks once all 4 cells are filled in ?

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need VB code to edit cell values Stephen Ford Microsoft Excel Programming 7 1st Jun 2010 10:55 AM
Attempted edit of protected cell jumps user to another cell megangomez Microsoft Excel Misc 2 6th Aug 2009 12:54 AM
determine when the user moves to a difference cell Sean Farrow Microsoft Excel Programming 1 16th Dec 2008 09:54 AM
Tweak to code that checks colors of fonts and moves to proper shee SCrowley Microsoft Excel Programming 0 4th Mar 2008 07:56 PM
when exiting combobox, this code moves the selected cell down two rows instead of one Harold Good Microsoft Excel Programming 0 6th Dec 2007 05:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:57 PM.