Excel First

Excel Solutions

Autoexpand Excel Tables on Protected Sheets

Autoexpand Excel Tables on Protected Sheets


An important feature of Excel Defined Tables, the autoexpanding functionality, is lost when the worksheet is protected. On a protected worksheet, when you type anything under the last row, the table will not automatically expand to include the new row, as you might expect. The decision to protect the sheet is not easy when you need both protection and autoexpansion capabilities for an Excel Table.

Most likely, Microsoft engineers are well aware of this limitation, but until they come up with a solution to this problem, you can try my solution. The solution involves a little Visual Basic programming, but fortunately for you, I have taken care of the programming part.

Using the Worksheet_SelectionChange event,

we can detect what cell is selected by a user, and then we can decide if we need to unprotect (or not) the worksheet.

The best thing is that we can protect from editing important columns from the table, if there are such columns in your table, and still take full advantage of the table autocomplete features.

In this sample workbook, I setup 2 columns where a user must “stay away” from, they are the blue columns in this image:

Protected Columns in Excel Table

Protected Columns in Excel Table

Important! To protect those columns, I simply set manually the Locked property of the cell to Locked (from the right click menu, Format cells, Protection tab, check the Locked checkbox).

The code will check the first cell from above the selected cell, it will reprotect the table if that cell is protected:

Download the sample workbook: Autoexpand table on protected sheet.xlsm

Here is the VBA code:

You will notice that I am opening and closing the Clipboard in this code.

The reason for this, is that when a code is triggered, the clipboard is cleared; if the Clipboard is open, Excel will fail to clear the clipboard, and whatever we copied before selecting a cell is still on the clipboard.

You can disable the code, if you need to make structural changes to the table, by setting the Enable or Disable option in the “Switch” worksheet.

The code will work in Excel 2007, 2010, and 2013; not tested in Excel 2003, but it should work there as well.

There are many possible situations that needs to be taken into consideration, like what happens if a user pasts multi column data into our table, overwriting protected columns?

With the existing code, it’s possible, but we can prevent that with another simple code:

If you found situations in which the code is not working as expected, send me the details, only together we can make things better 🙂 (where did i hear that??)

Have fun 🙂



10 Comments to Autoexpand Excel Tables on Protected Sheets

  1. Eduard says:

    This is exactly what I have been looking for all weekend and finally found it.

    But unfortunately I’m not able to try it as it starts the VBA editor and prompts an error message when opening the file.

    The error message is as followed:

    “Compile error:
    The code in this Project must be updated for use on 64-bit systems.
    Please review and update Declare statements and then mark them with the PtrSafe attribute.”

    • Hi Eduard,
      You have to replace the function declarations:
      Replace these 2 lines:

      With this:

      Or, you can download the sample workbook again, I updated the code for 64 bit systems.

  2. Nicolas says:


    it seems to be very effective for adding a new row, but with the macro running, I seems impossible to delete any row in the table.

    Did you face this issue?


    Best regards,


  3. Hi Caitlin.

    Unfortunately when sharing a spreadsheet using OneDrive, which allows multiple users to edit at the same time, by using the Edit in Browser option both VBA and macros are disabled. With this usage in mind is there any way to both protect formulas and allow the autoexpand functionality.
    I must be honest that Edit in Browser really restricts the functionality of Excel.


    • I’m afraid that there are no other options on OneDrive, that limitation can be bypassed only with VBA, but as you already know, the code will not work in browser.
      Hopefully they will add this functionality on protected sheets.

  4. Julian De Silva says:

    Hi Catalin

    The sample file that you have shared has a option to enable disable protection. My requirement is to keep the worksheet protected by default & should be able to enter data into the table and for it to get auto expanded. I dont want to have any buttons to enter new rows.

    All i want is to go on entering data into the protected sheet by auto expanding the table.

    I tried editing your code, but i messed it up big time. Appreciate your help on this.


Leave a Reply

Your email address will not be published. Required fields are marked *