Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default Select Cell within range

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Select Cell within range

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Select Cell within range

When you protect the sheet (assuming you are using XL2002 or better) then you
get a dialog that ask you how you want to protect the sheet. One item is the
ability to select locked cells. If you uncheck that then the user can not
select any cell you have locked.

As for displaying a user form you can either use a button or one of the cell
events. Selection chage can work as you have suggested. That will fire
whether or not the mouse, enter key or arrows are used. you could use the
double click event. In that case (IMO a better option) you can only pop the
form with the mouse...

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If Target.Address = "$B$2" Then
Cancel = True
UserForm1.Show
End If
End Sub
--
HTH...

Jim Thomlinson


"ranswrt" wrote:

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

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
macro to select range from active cell range name string aelbob Excel Programming 2 July 14th 08 09:19 PM
HELP W/ VBA: SELECT RANGE, ALLCAPS, CELL COLOR, RETURN TO BLANK CELL/PATTERN CELL [email protected] Excel Programming 5 June 28th 08 07:49 PM
NEED VBA TO SELECT A CELL; NOTE THE CELL VALUE;COPYADJ CELL;FIND CELL VALUE IN A RANGE AND SO ON CAPTGNVR Excel Programming 2 July 8th 07 04:18 PM
Select Cell Range Debra Ann Excel Programming 5 March 2nd 06 08:26 PM
select last cell in used range Tony P Excel Programming 1 January 7th 04 06:41 AM


All times are GMT +1. The time now is 01:37 PM.

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

About Us

"It's about Microsoft Excel"