Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Generate an event when a cell is pressed
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Generate an event when a cell is pressed
Here's an adaptation from a post from Tom Ogilvy that may be
appropriate to your situation. http://www.google.com/groups?hl=en&l...upernews.co m Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim strNew As String, strVal As String On Error GoTo errHandler If Target.Count 1 Then Exit Sub If Target.Column = 3 Then strNew = Target.Value If strNew = "" Then Exit Sub Application.EnableEvents = False Application.Undo strVal = Target.Value If InputBox("Password:") = "YourPassword" Then _ Target.Value = strNew End If errHandler: Application.EnableEvents = True End Sub Tested using Excel 97SR2 on Windows 98SE, HTH Paul -------------------------------------------------------------------------------------------------------------- Be advised to back up your WorkBook before attempting to make changes. -------------------------------------------------------------------------------------------------------------- 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
When enter key is pressed, cursor does not move to next cell in Ex | Excel Discussion (Misc queries) | |||
how do I change which cell becomes active when enter is pressed? | Excel Discussion (Misc queries) | |||
How to generate same event (has 2 possible outcomes) 200 times? | Excel Discussion (Misc queries) | |||
Enter button jumps to next cell each time its pressed!!!! | Excel Discussion (Misc queries) | |||
generate a random number and use if function to generate new data | Excel Worksheet Functions |