Name

Application.DataEntryMode [= setting]

Synopsis

Sets or returns whether or not Excel is in data-entry mode. Can be one of these settings:

xlOn

xlOff

xlStrict, prevents the user from exiting the mode by pressing Esc

Data-entry mode restricts users to unlocked cells. By default, cell protection is set to Locked, so you must unlock a range to demonstrate this feature. The following code restricts data entry to range A1:D4; the user can return to regular mode by pressing Esc, as shown by the following code:

Sub TestDataEntryMode(  )
    Range("a1:d4").Locked = False
    Application.DataEntryMode = xlOn
End Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.