+ Reply to Thread
Results 1 to 8 of 8

Hide and Unhide Columns

  1. #1
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Hide and Unhide Columns

    I have a sheet containing numerous columns. Some of the columns contain data that I don't want the user to see. Obviously I can simply hide the respective columns but this also means the user can easily unhide them.

    Is there a way to create a password protected macro (I don't know if macro's can be password protected?) that allows specific columns to be specified which can be hidden when run, e.g. columns F, I, K, L and J and then a second macro (if this is the best option) to unhide the columns.

    This would need to allow for the fact that the user 'could' insert their own additional columns into the sheet, so ideally the column references to be hidden/unhidden would need to automatically update in the macro (if this is even possible) to accommodate this.

    Obviously any data in the hidden columns would need to be sorted along with the rest of the sheet, should the user decide they want to sort by any of the visible columns.

    Many thanks

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,669

    Re: Hide and Unhide Columns

    It may be possible but it won't be easy. Firstly, if it is macro driven, then the user MUST enable macros. If they don't, then there is little/no protection. So, you have to make the workbook unusable if macros are not enabled. That requires a process of hiding/unhiding sheets on open, save and close of the workbook. Lots of examples around of using a "Splash" screen.

    Second, it is possible to hide columns using their column names. However, once again, this can be circumvented if the user changes column header names ... and you don't have to be able to see what is in a cell to change or delete it.

    Thirdly; yes, the hidden columns will be sorted when you sort the data.

    Fourth, it would be better to put sensitive information and calculations on a separate sheet and use a key field to link to it ... but that would depend on how the data is created and structured.

    Lastly, Excel is not a secure environment. Whatever you do to protect the "sensitive" information, it will be possible to unprotect it and make it visible.

    All in all, don't hold your breath for a solution that is safe and secure. There is unlikely to be one.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Hide and Unhide Columns

    Hi TMS,

    In terms of 'Safe and Secure' regarding 'Sensitive Information'. The data is all internal and my use of the word 'Sensitive' was perhaps not the best choice as in it can be seen by all without problem, but the logic of what I want to achieve is to simply restrict 'when' we make the information avbailable, hence the hidden columns approach, which I appreciate isn't foolproof. It is not the end of the world if the user were to see the hidden coumns, but I simply want to delay when.

    In response to your observations:

    With respect to the user enabling macro's, that isn't an issue as I can ensure they do that.

    Columns headers, these will be fixed, which of course doesn't prevent the user changing them, but they will have no need to do so. If it became an issue I could Data Validate the column headers or protect the cells.

    I don't know if that changes your view on whether this is possible to achieve?

    Many thanks

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Hide and Unhide Columns

    It's possible - upload a sample workbook.

    Re: TMS's remarks

    1) Agreed - use a splash screen, you cannot ensure they'll enable macros if you just trust their word on it ;-)
    2) Column header names can be secured with a worksheet_change event that resets the column header on each change. Alternatively, you can protect the cells & worksheet.
    3) Sorting if you set the sort area to include the hidden columns. Otherwise they won't (for example, if you'd have an empty column in there).
    4 & 5) I side with TMS
    Please click the * below if this helps

  5. #5
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Hide and Unhide Columns

    Okay, simplistic sample attached.

    Assume I want to 'hide' columns B, F & G with the ability to hide/Unhide using a macro as discussed...

    I take on board your comments...
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    08-15-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    349

    Re: Hide and Unhide Columns

    Something like this, password=123
    Attached Files Attached Files
    Please click the * Add Reputation if this helps
    If solved remember to mark Thread as solved

    "I'm glad to help and this is not meant to sound smart, but either you have super-human vision to see all those controls cleared one by one with the code I posted, or your computer is really slow."

  7. #7
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Hide and Unhide Columns

    Hi Blokeman,

    Seems to do the job perfectly... certainly for my needs.

    Many thanks for your help...

  8. #8
    Forum Contributor
    Join Date
    08-15-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    349

    Re: Hide and Unhide Columns

    No problem, glad to help and thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Hide/unhide columns that contain a certain value
    By noob85 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-13-2015, 06:22 PM
  2. VBA will hide columns, but not unhide them
    By JontyRhodes in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-16-2015, 12:54 PM
  3. Hide and Unhide Columns
    By DODGE in forum Excel General
    Replies: 3
    Last Post: 11-27-2011, 05:36 PM
  4. Hide/Unhide columns
    By N164PJ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-22-2008, 02:30 AM
  5. [SOLVED] Hide and unhide columns
    By Frederic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-14-2005, 05:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1