An OnEntry event handler runs when the user either enters data on a worksheet using the formula bar or edits data in a cell. You can use the OnEntry property of a Worksheet object to associate a procedure with the entry of data on any worksheet. You can use the OnEntry property of the Application object to associate the event handler with the entry of data on any worksheet in any open workbook. The event handler runs after the user enters data in a cell or in the formula bar and then either presses Enter, selects another cell, or clicks the enter box on the formula bar.
For example, the following code associates the OnEntry event with a procedure that validates the data entered in a cell in column B on the GeneCountDB worksheet.
Sub TrapEntry() ActiveWorkbook.Worksheets("GeneCountDB").OnEntry = _ "ValidateColB" End Sub Sub ValidateColB() With ActiveCell If .Column = 2 Then 'Test for second column. If IsNumeric(.Value) Then If .Value < 0 Or .Value > 255 Then MsgBox "Entry must be between 0 and 255." .Value = "" End If Else 'Handle non-numeric entry MsgBox "Entry must be a number between 0 and 255." .Value = "" End If End If End With End Sub
Note
The OnEntry event handler doesn't run if you enter data in a cell by clicking either Cut, Copy, or Paste on the Edit menu, or if you change the contents of a cell under program control.