Article ID: 139663
Article Last Modified on 10/11/2006
Sub auto_open()
'Set the WatchIT macro to run when data is entered into Sheet1
ThisWorkbook.Sheets("Sheet1").OnEntry = "WatchIT"
End Sub
Sub WatchIT()
Dim isect As Excel.Range
Set isect = Application.Intersect(Range(ActiveCell.Address), _
Range("WatchArea"))
If isect Is Nothing Then
'Do Nothing
Else
'You just entered into the defined area "WatchArea" on
'"Sheet1" add other the desired action code here or call
'another routine.
'Example below will alert the user if the data value is less
'than 0 or greater than 100 or is not a number and clear the
'entry. It will also give a confirmation beep when valid
'data is entered.
If (Val(ActiveCell.Value) < 0 _
Or Val(ActiveCell.Value) > 100) _
Or Not IsNumeric(ActiveCell.Value) Then
ActiveCell.Clear
MsgBox "The data value must be a Number between 0 and 100"
End If
Beep
End If
End Sub
NOTE: To customize this macro, change the "Sheet1" sheet name to the
name of the sheet you want to "watch." Also, modify the "WatchArea" name
in the WatchIT macro to the name of the defined area on the sheet
specified in the auto_open routine. Use the Application.OnEntry code to
"watch" data entry in all open workbooks and worksheets. You can also
use the WorkBooks collection to qualify a specific workbook if desired.
data validation, preventing incorrect entry
OnEntry
-or-
Intersect
Additional query words: 8.00 97 Data Entry Validate XL
Keywords: kbdtacode kbhowto kbprogramming KB139663