Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Disable access to lock cells in a worksheet

Posted on 2008-06-25
6
Medium Priority
?
706 Views
Last Modified: 2010-04-21
I have disabled access to certain cells in a spreadsheet through a macro but it appears that the option to select the locked cells is still on.  What do I do to correct this?  I have attached my macro for reference.
If FormatCustomer Then
               Workbooks.Open Filename:="C:\my documents\Customers.xls"
               'Format IDs as General
               Range("C:C,E:E,F:F").Select
               Selection.NumberFormat = "General"
               'Set font to nine pitch
               Cells.Select
                    With Selection.Font
                    .Name = "Tahoma"
                    .Size = 9
                    .Strikethrough = False
                    .Superscript = False
                    .Subscript = False
                    .OutlineFont = False
                    .Shadow = False
                    .Underline = xlUnderlineStyleNone
                    .ColorIndex = 1
                    End With
               'Set Columns to autofit
               Cells.Select
               Selection.Columns.AutoFit
               'Rename tab sheet1 to Customers
               Sheets("Sheet1").Select
               Sheets("Sheet1").Name = "Customers"
               'Define Name Billto
               rowa = Sheets("Customers").Cells(Rows.Count, 1).End(xlUp).Row
               ActiveWorkbook.Names.Add Name:="Billto", RefersToR1C1:="=Customers!R2C2:R" & rowa & "C2" & Chr(32)
               'Define Name BillToList
               rowb = Sheets("Customers").Cells(Rows.Count, 1).End(xlUp).Row
               ActiveWorkbook.Names.Add Name:="BillToLookup", RefersToR1C1:="=Customers!R2C1:R" & rowb & "C8" & Chr(32)
               'Define Name BillToLookup
               ActiveWorkbook.Names.Add Name:="BillToList", RefersToR1C1:="=OFFSET(Customers!R2C1,0,0,COUNTA(Customers!C1)-1)"
               'Protect Customers Worksheet
               ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="password"
               ActiveSheet.EnableSelection = xlLockedCells
               'Go to first cell on worksheet
               Range("A1").Select
               'Save with same name as opened
               ActiveWorkbook.Save
            End If

Open in new window

0
Comment
Question by:ilrosebud26
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 

Author Comment

by:ilrosebud26
ID: 21867256
I am assuming that reason I am have a problem is the when the workbook is created by default bot the select lock and unlocked cells is on.  I think I need to disable locked cells instead of enable unlocked cells.  I just cannot find the right syntac to complete the task.
0
 
LVL 7

Expert Comment

by:TRobinJames
ID: 21876674
Are you sure about this statement:

ActiveSheet.EnableSelection = xlLockedCells

Perhaps you want:

ActiveSheet.EnableSelection = xlUnlockedCells

so that users can select only unlocked cells.  I am not use xlLockedCells is a valid excel constant and may be defaulting to 0 which is  xlNoRestrictions
0
 
LVL 7

Expert Comment

by:TRobinJames
ID: 21876707
Actually, sorry xlLockedCells is of course valid, however, I am not sure you want to use it in this case.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:ilrosebud26
ID: 21887112
No, you are correct.  It should say xlUnlockedCells orxlNoRestrictions.  My problem is that even when it says either of these, the locked cells can be selected but not changed.  If I unselect the locked cell box through tools/protection the users cannot even select the cells that are locked.  I want to replicate this functionality.  Is that possible or this base functionality of the application?
0
 
LVL 7

Accepted Solution

by:
TRobinJames earned 700 total points
ID: 21925882
Sorry, was out of office for a week.  If this is still relevant, the code below does not allow user to select or enter into cells, but allows selection of all cells outside range.
With ActiveSheet
    
    .Range("C9:E11").Locked = True
    .Protect
    .EnableSelection = xlUnlockedCells
End With

Open in new window

0
 

Author Closing Comment

by:ilrosebud26
ID: 31470637
I was also out of the office.  Thanks for your help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question