Event When Cell Entered

M

maxhugen

I'm trying to find a way to trigger an event when a cell is entered.

I have a cell (named "Client_Name") which by default has the tex
"Please enter name" in it.

When a user clicks into the cell, I'd like to set the cell to empty, o
an empty string, so that it's ready to accept client data entry.

Any suggestions would be most appreciated!

MTI
 
F

Frank Kabel

Hi
try the following code. Put this in your worksheet module:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Range("A:A"), Target) Is Nothing Then Exit Sub
On Error GoTo errhandler
Application.EnableEvents = False
If LCase(Target.Value) = "please enter name" Then
Target.ClearContents
End If
errhandler:
Application.EnableEvents = True
End Sub
 
M

maxhugen

Thanks Frank!

Had a bit of a problem as I'd merged 2 cells for the client name, bu
once I unmerged the cells, it was AOK.

I do quite a bit of VB programming in Access mainly, but not much i
Excel. I thought the Intersect() you suggested was a good solution.

Many thanks, mate! Have a good day.

Cheers, Ma
 
J

JMay

Frank:
I can't get this to work for me;
On Sheet1 and in cell B7 I have entered please enter name
Posted your code; I've clicked on cell B7 arrowed into it
jumped up and down on it, but nothing happens "I thought it was suppose
to clear once I did any one of these things...
Confused here, any suggestions??
JMay


Frank Kabel said:
Hi
try the following code. Put this in your worksheet module:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Range("A:A"), Target) Is Nothing Then Exit Sub
On Error GoTo errhandler
Application.EnableEvents = False
If LCase(Target.Value) = "please enter name" Then
Target.ClearContents
End If
errhandler:
Application.EnableEvents = True
End Sub
 
F

Frank Kabel

Hi
you have to adapt the range reference in the procedure:
change
If Intersect(Range("A:A"), Target) Is Nothing Then Exit Sub

to
If Intersect(Range("B1:B10"), Target) Is Nothing Then Exit Sub
 
Top