Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
When enter key is pressed, cursor does not move to next cell in Ex Blackie Excel Discussion (Misc queries) 3 April 19th 23 02:10 PM
how do I change which cell becomes active when enter is pressed? scotpiper Excel Discussion (Misc queries) 1 April 7th 09 12:18 AM
How to generate same event (has 2 possible outcomes) 200 times? lnwdros Excel Discussion (Misc queries) 1 November 17th 08 02:28 AM
Enter button jumps to next cell each time its pressed!!!! evasmagacz Excel Discussion (Misc queries) 3 June 17th 07 08:37 PM
generate a random number and use if function to generate new data Dogdoc1142 Excel Worksheet Functions 4 April 26th 06 03:44 AM


All times are GMT +1. The time now is 06:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"