+ Reply to Thread
Results 1 to 8 of 8

Need to auto hide columns when exiting!

  1. #1
    Registered User
    Join Date
    02-20-2020
    Location
    Leeds Uk
    MS-Off Ver
    7
    Posts
    4

    Need to auto hide columns when exiting!

    Hi.

    I have a worksheet that is shared between employee's which has some columns that has some sensitive data shown.

    I need these to be hidden when the sheet is opened, but when the sheet is unlocked by myslef, I can then unhide the columns.

    So far I have managed to do... However I was thinking, if I forgot to hide these confidential columns when exiting, they would be seen if someone else opened t.

    So, in an ideal world, when exiting, I need the sheet to auto hide 3 columns so that when the next person logs on they are not visible...

    Any ideas?


    Peter
    Last edited by AliGW; 02-20-2020 at 07:38 AM. Reason: Irrelevant section of title removed: this is a HELP forum!!!

  2. #2
    Valued Forum Contributor
    Join Date
    08-03-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2007, 2010, 2013, 2016, Office 365
    Posts
    467

    Re: Need to auto hide columns when exiting!

    Hi Peter

    You just need to add some code in the Workbook module and save you file as a macro-enabled file e.g. .xlsm format

    This code would make sure columns [H:M] are hidden on sheet named "xxx" ; adjust to suit..
    Please Login or Register  to view this content.
    zeddy

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Need to auto hide columns when exiting!

    Put this in the ThisWorkbook code module

    Change the sheet name, columns, and sheet password to suit

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Valued Forum Contributor
    Join Date
    08-03-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2007, 2010, 2013, 2016, Office 365
    Posts
    467

    Re: Need to auto hide columns when exiting!

    Hi Peter

    I need these to be hidden when the sheet is opened
    ..you can also use the Workbook_Open() event to do this

    zeddy

  5. #5
    Registered User
    Join Date
    02-20-2020
    Location
    Leeds Uk
    MS-Off Ver
    7
    Posts
    4

    Re: Need to auto hide columns when exiting!

    Thanks Guys, will give it a try now!

  6. #6
    Registered User
    Join Date
    02-20-2020
    Location
    Leeds Uk
    MS-Off Ver
    7
    Posts
    4

    Re: Need to auto hide columns when exiting!

    Thanks.

    I have tried this as shown below

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

    With ThisWorkbook.Sheets("Sheet1")
    .Unprotect Password:="Secret"
    .Columns("OD:OS").Hidden = True
    .Protect Password:="Secret"
    End With

    End Sub

    But when I then go to save the document it says

    Runtime Error 9

    Subscript out of range



    Any ideas?

  7. #7
    Valued Forum Contributor
    Join Date
    08-03-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2007, 2010, 2013, 2016, Office 365
    Posts
    467
    Change "Sheet1" to the name in the tab for your actual worksheet.

    zeddy

  8. #8
    Registered User
    Join Date
    02-20-2020
    Location
    Leeds Uk
    MS-Off Ver
    7
    Posts
    4

    Re: Need to auto hide columns when exiting!

    Thanks Mate...

+ 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. [SOLVED] Auto hide columns macro
    By raza_m33hdy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-28-2013, 11:01 AM
  2. [SOLVED] Auto Hide Columns
    By msmac74 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 10-26-2012, 07:25 AM
  3. [SOLVED] Auto Hide Date Columns--NEED HELP!!
    By abusby in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-22-2012, 03:53 PM
  4. auto hide and protect columns
    By drocket in forum Excel General
    Replies: 4
    Last Post: 01-26-2007, 02:51 AM
  5. Auto-Hide Columns
    By Brian Matlack in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2006, 11:42 AM
  6. [SOLVED] Auto hide/Unhide columns
    By Vespaguy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-20-2006, 01:40 PM
  7. [SOLVED] Auto Hide Columns
    By Phil Osman in forum Excel General
    Replies: 5
    Last Post: 03-28-2005, 12:08 AM
  8. Auto Hide Columns & Rows
    By appeng in forum Excel General
    Replies: 2
    Last Post: 03-25-2005, 01:06 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