Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Data Validation

I have been using data Validation to alert users when data
is input incorrectly. However, rows need to be inserted
into the middle of the spread sheet and formulas pasted in
those rows. So my warnings are getting knocked off.

Can I do the same with a macro? Running for the whole
column and all the time?

If data entered in Column H: A message box saying "Must
Use Valid Date"

If Cell is used in D2 and not its precedent cell in C2 A
message Box saying "Must Enter Depreciation Period"


Thanks, Todd
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Data Validation

How about a worksheet change event, right click on that worksheet tab that
should have this behavior. Select view code and paste this in:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim DateRng As Range
Dim DepRng As Range
Dim myCell As Range

On Error Resume Next
Set DateRng = Intersect(Target, Range("H:H"))
Set DepRng = Intersect(Target, Range("d:d"))
On Error GoTo 0

On Error GoTo errHandler:

If DateRng Is Nothing Then 'didn't touch column H
'do nothing
Else
For Each myCell In DateRng.Cells
Application.EnableEvents = False
If IsEmpty(myCell.Value) _
Or IsDate(myCell.Value) Then
'do nothing
Else
myCell.ClearContents
MsgBox myCell.Address(0, 0) & " Must be a valid date!"
End If
Next myCell
End If

If DepRng Is Nothing Then 'didn't touch column D
'do nothing
Else
For Each myCell In DepRng.Cells
Application.EnableEvents = False
If IsEmpty(myCell.Value) = False _
And IsEmpty(myCell.Offset(0, -1).Value) Then
myCell.ClearContents
MsgBox "Must Enter Depreciation Period in " _
& myCell.Offset(0, -1).Address(0, 0)
End If
Next myCell
End If

errHandler:

Application.EnableEvents = True

End Sub


If the user disables events (or just says no to enable macros), then this won't
work.


Todd wrote:

I have been using data Validation to alert users when data
is input incorrectly. However, rows need to be inserted
into the middle of the spread sheet and formulas pasted in
those rows. So my warnings are getting knocked off.

Can I do the same with a macro? Running for the whole
column and all the time?

If data entered in Column H: A message box saying "Must
Use Valid Date"

If Cell is used in D2 and not its precedent cell in C2 A
message Box saying "Must Enter Depreciation Period"

Thanks, Todd


--

Dave Peterson

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
custom data validation on cells with data validation values AKrobbins Excel Worksheet Functions 2 June 21st 11 04:20 PM
Validation Data using Validation Table cell range..... Dermot Excel Discussion (Misc queries) 16 January 5th 10 09:35 PM
data validation invalid in dynamic validation list ilia Excel Discussion (Misc queries) 0 November 7th 06 12:54 PM
data validation invalid in dynamic validation list ilia Excel Worksheet Functions 0 November 7th 06 12:54 PM
Data validation with validation lists and combo boxs Keith Excel Discussion (Misc queries) 1 October 12th 06 11:08 AM


All times are GMT +1. The time now is 10:26 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"