I hate to "throw a wrench into the monkeyworks", but:
 
you were trying to use the SheetSelectionChange event.
which actually runs for ANY sheet in your workbook, not just a specific sheet.
 
which might be a bit confusing if you have multiple sheets,
and you're using the event macro to "lock" the cells, then it would actually 
lock the cells the other sheets as well..
 
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As 
Range)
 
If you only want the macro to run on a specific sheet, you can either test the 
Sh object for the sheet name.
Or you can create a similar event macro in the sheet module called:
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Next, if you're wanting to "lock" cells A1:P9, you could use something like:

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As 
Range)
    Dim Targ As Range
    For Each Targ In Target
        If (Not Intersect(Targ, Sh.Range("A1:P8")) Is Nothing) Then
            Sh.Range("A9").Select
            Exit For
        End If
    Next Targ
End Sub

One thing I've run into is that if you select multiple cells, the "Target" 
variable becomes an array instead of a simple object.
So I use the Targ variable to loop through the Target selection array.
This works if you select a single cell or multiple.

In this case, I look for the "intersection" of the selected cell and the 
"locked" range.
If the cell is within the blocked range, it returns the range.
(or "Not nothing")

in which case I selce another cell (which, incidentally calls this event again)

The nice thing about this is that if you wish to change the values of the 
"blocked" cells using VBA, you don't actually "select" the cell, you simply 
have to use something like:

Range("A2").value = "Test"

something else you need to be aware of is that the "Target" variable 
a range variable, but the address is in "absolute" terms.
That is, if you select cell A9, Target.Address is $A$9

So, if you want to test to see if the selected cell is A9, you could use either:

If (Targ.Address = "$A$9") then

or even:

If (Targ.Row = 9) and (Targ.Column = 1) then

Paul
-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
-----------------------------------------

 From: Robert Baer <robertgurrb...@gmail.com>
>To: excel-macros@googlegroups.com 
>Sent: Wednesday, October 22, 2014 12:57 PM
>Subject: Re: $$Excel-Macros$$ Re: How can one control data entry and truly 
>protect a verified entry
>  
>
>
>  WOW!
>  That works!
>  Thanks a lot!
>  Attempted to try:
>Private Sub Workbook_SheetSelectionChange(ByVal WkSh As Object, ByVal AmAt As 
>Excel.Range)
> ' Supposedly runs when a sheet selection (cell?) is changed.
>    whatName = WkSh.Name: wheregot = AmAt
>    If wheregot <> CellLoc Then
>     X = X  ' set as a breakpont; NEVER happens
>    End If
>End Sub
>  ..which never executed, so that idea was DOA.
>
>  The Application.InputBox() is perfect.
>  Thanks again.
>
>On Wednesday, October 22, 2014 2:00:11 AM UTC-7, Vabz wrote:
>you can use this to work on VBA
>>
>>
>>Sub RB()
>>
>>
>>Dim Avar As String, Nvar As Long
>>Dim Frow As Integer, Fcol As Integer
>>' Start row data entry
>>    Frow = 9: Fcol = 1 ' aka "A"
>>    Cells(Frow, Fcol).Select
>>    Avar = Application.InputBox("Enter value!!", Type:=3)
>>    ' want to wait for user entry; obviously i now have a wait working, 
>> BUT.....
>>' stays in this loop forever; user CANNOT enter anything!
>>    ActiveCell.FormulaR1C1 = UCase$(Avar)
>>    Fcol = Fcol + 1 'now $B$9
>>    Nvar = 0
>>    While Nvar = 0
>>     Nvar = ActiveCell.FormulaR1C1
>>     ' check alfa?
>>    Wend
>>    
>>End Sub
>>
>>
>>
>>
>>+++++
>>I did not do this for you. God is here working through me for you.
>> 
>>
>>On Tue, Oct 21, 2014 at 12:39 AM, Robert Baer <robertg...@gmail.com> wrote:
>>
>>
>>>
>>>On Monday, October 20, 2014 12:48:25 AM UTC-7, Vabz wrote:
>>>Hi can you share sample files...
>>>>
>>>>
>>>>+++++
>>>>
>>>>
>>>
>>>Here is what i have so far..present question imbedded
>>>Dim Avar As String, Nvar As Integer
>>>Dim Frow As Integer, Fcol As Integer
>>>' Start row data entry
>>>    Frow = 9: Fcol = 1 ' aka "A"
>>>    Cells(Frow, Fcol).Select
>>>    Avar = ""
>>>    While Avar = ""
>>>' CellLoc = ActiveCell.Address      ' eg: $A$9
>>>     Avar = ActiveCell.FormulaR1C1  ' eg: user enters "88"
>>>
>>>' want to wait for user entry; obviously i now have a wait working, BUT.....
>>>' stays in this loop forever; user CANNOT enter anything!
>>>
>>>    Wend
>>>    ActiveCell.FormulaR1C1 = UCase$(Avar)
>>>    Fcol = Fcol + 1 'now $B$9
>>>    Nvar = 0
>>>    While Nvar = 0
>>>     Nvar = ActiveCell.FormulaR1C1
>>>     ' check alfa?
>>>    Wend
>>>    
>>>    
>>>    x = x '<-- Justin Case break point for debugging 
>>>** Thanks
>>>
>>>-- 
>>>Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
>>>=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
>>>https://www.facebook.com/discussexcel
>>> 
>>>FORUM RULES
>>> 
>>>1) Use concise, accurate thread titles. Poor thread titles, like Please 
>>>Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will 
>>>not get quick attention or may not be answered.
>>>2) Don't post a question in the thread of another member.
>>>3) Don't post questions regarding breaking or bypassing any security measure.
>>>4) Acknowledge the responses you receive, good or bad.
>>>5) Jobs posting is not allowed.
>>>6) Sharing copyrighted material and their links is not allowed.
>>> 
>>>NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
>>>members are not responsible for any loss.
>>>--- 
>>>You received this message because you are subscribed to the Google Groups 
>>>"MS EXCEL AND VBA MACROS" group.
>>>To unsubscribe from this group and stop receiving emails from it, send an 
>>>email to excel-macros...@ googlegroups.com.
>>>To post to this group, send email to excel-...@googlegroups.com.
>>>
>>>Visit this group at http://groups.google.com/group/excel-macros.
>>>For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>-- 
>Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
>=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
>https://www.facebook.com/discussexcel
> 
>FORUM RULES
> 
>1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
>Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
>quick attention or may not be answered.
>2) Don't post a question in the thread of another member.
>3) Don't post questions regarding breaking or bypassing any security measure.
>4) Acknowledge the responses you receive, good or bad.
>5) Jobs posting is not allowed.
>6) Sharing copyrighted material and their links is not allowed.
> 
>NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
>members are not responsible for any loss.
>--- 
>You received this message because you are subscribed to the Google Groups "MS 
>EXCEL AND VBA MACROS" group.
>To unsubscribe from this group and stop receiving emails from it, send an 
>email to excel-macros+unsubscr...@googlegroups.com.
>To post to this group, send email to excel-macros@googlegroups.com.
>Visit this group at http://groups.google.com/group/excel-macros.
>For more options, visit https://groups.google.com/d/optout.
>
>
>    

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to