View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
ranswrt ranswrt is offline
external usenet poster
 
Posts: 191
Default Select Cell within range

Thanks I'll give it try

"Rick Rothstein" wrote:

You can still protect your worksheet and allow the user to select any cells,
then use SelectChange to decide if the selection was alright or not. Here is
some code that will confine the user's selection to an allowed range; for
example, if they click in the allowed range (D4:H8 is the example range
implemented in my code below), then you can show your UserForm (replace my
MsgBox statement with your own code), otherwise the code below returns the
selection to the top left cell of the AllowedRange.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const AllowedRange As String = "D4:H8"
On Error GoTo OnceOnly
Application.EnableEvents = False
If Not Intersect(Target, Range(AllowedRange)) Is Nothing Then
MsgBox "Range OK - You can call show your UserForm"
Else
With Range(AllowedRange)
Cells(.Row, .Column).Select
End With
End If
OnceOnly:
Application.EnableEvents = True
End Sub


--
Rick (MVP - Excel)


"ranswrt" wrote in message
...
I am try to write a procedure to start a userform when a cell is clicked.
I
am using the selection change event in the worksheet. I need to keep the
cells locked to protect the contents in them. Is there a way to protect
the
sheet but only allow cells within a range to be selected not all the cell
on
the worksheet? Or is there another way to have userform start up by
clicking
or double clicking a cell?
Thanks