Generate an event when a cell is pressed
Hi Irfan
No, when you start writing in a cell, Excel enters "insert" mode and no
event or code runs. But with a little awkward programming you can perhaps
authorize the changes afterwards. Here's a humble start, put into the sheet
module:
Option Explicit
Dim LastCel As Range
Dim LastContent As String
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Not LastCel Is Nothing Then
If LastCel.Formula < LastContent Then
If InputBox("Password:") < "Pwd" Then _
LastCel.Formula = LastContent
End If
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set LastCel = Target(1)
LastContent = LastCel.Formula
End Sub
--
HTH. Best wishes Harald
Followup to newsgroup only please
"irfan" skrev i melding
om...
Hello All,
I want to generate an event when a user presses a key on the keyboard
or in other words if a user changes the content of a cell.
What i actually want to do is to ask a user for password if a user
changes
the contents of a cell.
Contents of a cell can be changed either by doublecliking by mouse or
directly pressing the keys. I can handle former by using
beforedoubleclick event and then ask user the password, but i am not
able to control the keypress event.
is there any keypress event or other way to do this. Any help is
appreciated.
TIA
Irfan
|