+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Forum Guru Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    5,139

    Re: Conditionally Hide Columns

    Hi Gos

    Sorry about the delay. Got called away.

    Try this out.

    I don't know what cells to lock and what your list drop downs rules are (I may have lost some while testing)

    1/. I have added column "Q" to the macro activation, it should hide the columns based on "D" in the same row, as does column "D" with "Q".

    Don't know if you need this, but it seemed logical to me. It is fairly obvious how to cancel this.

    2/. I have made your new button toggle hide/unhide columns "S:CQ"

    3/. The sheet will be protected when it is opened. To make changes to the sheet use unprotect (Password = "test") don't protect it again. Save/Close/Re-open to check changes. Same with changing the password in ThisWorkbook

    4/. You should also Password protect the VBa to prevent any adventurous user going into the code and finding sheet Password.

    Let me know how you get on.

    Regards
    Alistair
    Attached Files Attached Files

  2. #17
    Valued Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    343

    Thumbs up Re: Conditionally Hide Columns

    Looks good! Thanks a million!

    I will test it thoroughly and get back to you later.

    Gos-C
    Using Excel 2007 & 2010/Windows XP

    "It is better to be prepared for an opportunity and not have one than to have an opportunity and not be prepared."

  3. #18
    Valued Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    343

    Re: Conditionally Hide Columns

    Hi Marcol,

    I had some users test the sheet and they found that I made a few errors in parts of the logic.

    I modified the code a bit, but I can’t get it to work like it should. If you can help me fix it, that would be great.

    1. The Toggle Columns button should hide/unhide column Q together with columns U:CQ. Note: Columns S:T must always be shown when the toggle button is used. (Can you please verify that I coded it correctly.)

    2. For column D, there should be three cases – each with different columns being hidden: (1) CM; (2) LR, MG and NR; and (3) CR, GN, PA and SC. (Can you please verify that I modified the code correctly.)

    3. Columns S:T should be hidden when CM, LR, MG or NR is selected, and unhidden when any other code is selected. (Can you please verify that I modified the code correctly.)

    4. If the user deletes the contents of a cell in column D, the contents of the cells in columns Q and S:CQ for that row should be deleted, and all columns unhidden.

    5. Instead of:
    ‘if delete is used (in column Q) then unhide all columns and exit,

    can it be:

    ' if delete is used (in column Q) then unhide the columns that were hidden (in other words, show the columns that were shown) when that selection was originally made and exit

    In other words, when the user deletes the contents of a cell in column Q, the macro should unhide the columns that were hidden when that selection was made – effectively, reverting to the columns that were shown when the log code in column D (for that row) was selected. For example, if the user selects LR in column D, and “Exceeds plan limit” in column Q, but later deletes ”Exceeds plan limit” in column Q, the columns that were hidden when “Exceeds plan limit” was selected, should be unhidden.

    Also, can you please explain “isect”? It’s the first time I am seeing it in macros.

    Thanks again for your help.

    Regards,
    Gos-C
    Attached Files Attached Files
    Using Excel 2007 & 2010/Windows XP

    "It is better to be prepared for an opportunity and not have one than to have an opportunity and not be prepared."

  4. #19
    Forum Guru Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    5,139

    Re: Conditionally Hide Columns

    1/. The Toggle Columns button should hide/unhide column Q together with columns U:CQ.
    Changes
    I have added "Q" to the if statement to define the exact condition to toggle under.
    I have changed the Toggle Button caption to suit.

    2/. For column D, there should be three cases
    Changes
    None - Your code modification is fine.

    3/. Columns S:T should be hidden when CM, LR, MG or NR is selected, and unhidden when any other code is selected.
    Changes
    I have added Columns("S:T").Hidden = False to Case "CR", "GN", "PA", "SC" to fullfill the unhidden condition.

    4/. If the user deletes the contents of a cell in column D, the contents of the cells in columns Q and S:CQ for that row should be deleted, and all columns unhidden.
    Changes
    I have added code to handle this condition. It will require testing to cover possible user situations I am unaware of
    Note the use of Application.EnableEvents = False/True in this additional code.

    5/. Instead of: ‘if delete is used (in column Q) then unhide all columns and exit,.........
    Changes
    I have added code to handle this condition.
    Code in 4/. will override this on occassions , this is unavoidable, but it is probably correct to do so.

    In most of the above, I cannot say for sure that the result is correct, I cannot verify the required conditions, only you can do this.
    The methods used, however, should put you on the right track.

    6/. Also, can you please explain “isect”? It’s the first time I am seeing it in macros.
    This is the variable name Set by the Intersect function.
    In this line
    Code:
    Set isect = Application.Intersect(Target, Range("D:D,Q:Q"))
    Highlight Intersect press f1 to see an explaination by microsoft

    In my experience Worksheet_Change is seldom used without it.

    Help in Excel VBa is invaluable it contains a mine of information. Use it!!!

    I have attached an amended workbook for your evaluation.

    Please let me know how you get on with it.

    Regards
    Alistair

    If this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody!
    Also
    If you are satisfied by any members response to your problem please consider using the scales icon top right of thier post to show your appreciation.
    Attached Files Attached Files

  5. #20
    Valued Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    343

    Re: Conditionally Hide Columns

    Thank you, Marcol. I have to run out to clear my pool table at Canada Customs so I will get back to you later.

    Gos-C
    Using Excel 2007 & 2010/Windows XP

    "It is better to be prepared for an opportunity and not have one than to have an opportunity and not be prepared."

  6. #21
    Valued Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    343

    Thumbs up Re: Conditionally Hide Columns

    Hi Marcol,

    It is working fine now. Thank you very much for you help. I greatly appreciate it.

    Kindest regards,
    Gos-C
    Using Excel 2007 & 2010/Windows XP

    "It is better to be prepared for an opportunity and not have one than to have an opportunity and not be prepared."

  7. #22
    Forum Guru Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    5,139

    Re: Conditionally Hide Columns

    Glad to have been of some help

    Enjoy your pool ....... with beer?.....

    Cheers
    Alistair

    If this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody!
    Also
    If you are satisfied by any members response to your problem please consider using the scales icon top right of thier post to show your appreciation.

Thread Information

Users Browsing this Thread

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

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.2.0