Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am writng some code to validate dates entered. I have some code that
works in combobox_lost focus. It compares a date in a cell H12 to the date generated from the combobox. But if the user selects the value from the combobox, prior to entering value in the cell, validation will be skipped. I want to create some code that when the value in cell H12 changes, my code is triggered to validate dates. The code should only be triggered when cell H12 changes. Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim Workdate As Range Dim Result as Interger 'Msgbox result Set Workdate = Range("H12") If Intersect(Range("H12"), Target) Is Nothing Then Exit Sub Else ValidateDates End If End Sub Private Sub ValidateDate() Dim Workdate, StartDate, ExpirationDate As Date Dim Result As Integer With ActiveSheet Workdate = .Range("H12").Value StartDate = .Range("N8").Value ExpirationDate = DateAdd("yyyy", 1, StartDate) - 1 'Test if workdate enter is within contract effective dates If Workdate = StartDate And Workdate <= ExpirationDate Then Exit Sub Else Result = MsgBox("The work date does not fall within the selected contract period. Are you sure you want to use this contract?", _ vbQuestion + vbOKOnly, "CCF, Inc.") End If Thanks |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
how to use selectionchange instead of doubleclick event? | Excel Discussion (Misc queries) | |||
Worksheet SelectionChange Event | Excel Discussion (Misc queries) | |||
Disable SelectionChange Event | Excel Discussion (Misc queries) | |||
Excel Automation SelectionChange event | Excel Discussion (Misc queries) | |||
selectionchange problem | Excel Programming |