XL: EnableSelection Property May be Overridden

ID: Q157102

The information in this article applies to:

SYMPTOMS

If you use the EnableSelection property of a worksheet to restrict certain cells from being selected, you may still be able to select the restricted cells. For example, if you use the following code to prevent selection of locked cells:

   ActiveSheet.EnableSelection = xlUnlockedCells

it may still be possible to select locked cells.

CAUSE

This occurs because the EnableSelection property does not prevent you from selecting cells using the Name box on the Formula bar.

Also, you can use a macro to select cells, even if they are locked, by using a line of code similar to the following:

   Range("B5").Select

RESOLUTION

Even though you can select restricted cells, if the cells are locked and the worksheet is protected, you cannot change them.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.

MORE INFORMATION

You can use the EnableSelection property of a worksheet to determine what, if any, cells on a worksheet may be selected by the user. EnableSelection has three possible values:

   Value              Definition
   ---------------------------------------------------------------------

   xlNoRestrictions   Any cell can be selected.
   xlNoSelection      No cells can be selected.
   xlUnlockedCells    If the worksheet is protected, only cells that are
                      unlocked can be selected.

You can unlock a cell or group of cells by following these steps:

1. Select the cell(s) to be unlocked.

2. On the Format menu, click Cells. Click the Protection tab.

3. Clear the Locked check box. Click OK.

If the worksheet is protected and you have set the EnableSelection property to xlUnlockedCells, you cannot select locked cells, either by clicking them with the mouse or by using the Go To dialog box.

However, you can select locked cells by using the Name box on the Formula bar. If you click the Name box, type in a cell reference (D5, for example) or a range reference (D5:E10, for example), and then press Enter, the indicated cell or range will be selected.

Because the cells are locked and the worksheet protected, they cannot be changed. You can still copy or fill from a locked cell into unlocked cells without receiving any error messages.

Additional query words: XL97 XL98 vba vbe

Keywords          : kbdta xlformat KbVBA 
Version           : WINDOWS:97; MACINTOSH:98
Platform          : MACINTOSH WINDOWS

Last Reviewed: January 2, 1999