+ Reply to Thread
Results 1 to 13 of 13

Hide/Display selected columns

  1. #1
    Registered User
    Join Date
    07-13-2009
    Location
    Kuala Lumpur
    MS-Off Ver
    Excel 2003
    Posts
    11

    Hide/Display selected columns

    Somebody please help me!

    My boss wants me to create a macro to hide columns if there is a "X" on top of the column labels. The macro should be in toggle mode whereby the next pressing of the macro will unhide the hidden column.

    There are more than 50 columns in my actual worksheet. The macro has to check column by column whether there is "X" marked on top and hide it if so.

    The next pressing of the macro should then unhide all the hidden columns.

    Anyone, please help??

    Thank you so much!!!

    Jennifer
    Attached Files Attached Files
    Last edited by jenteh; 07-14-2009 at 06:17 AM.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Hide/Display selected columns

    You need two macros.

    The first sub a(), hides the column if there's an X in Row 3

    The second unhides all columns.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Hide/Display selected columns

    You can actually amend sweep's code to toggle the views
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Hide/Display selected columns

    Hi Roy,

    How does that work?

    Dave

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Hide/Display selected columns

    Hi Sweep

    The code simply reverses the Visible staus of the colmns
    Please Login or Register  to view this content.

  6. #6
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Hide/Display selected columns

    Roy,

    So this:

    Please Login or Register  to view this content.
    Is saying "if it's False make it True" and "if it's True, make it False"?

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Hide/Display selected columns

    Quote Originally Posted by sweep View Post
    Roy,

    So this:

    Please Login or Register  to view this content.
    Is saying "if it's False make it True" and "if it's True, make it False"?
    That's right

    I also use Option Compare text to make it case insensitive

  8. #8
    Registered User
    Join Date
    07-13-2009
    Location
    Kuala Lumpur
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Hide/Display selected columns

    Thank you Sweep! Thank you RoyUK! You guys are great!!

    There is something else I forgot to say. The "X" is not in row 3 only. It can be on any rows of the worksheet.

    Let's say when I place my cursor on row 12, I want to detect "X" on row 12. And if I place the cursor on row 30, I want to detect "X" on row 30, etc etc.

    So, the macro should detect the cursor position.

    Look forward to great help from you guys again.

    Million thanks!!!!
    Jennifer

  9. #9
    Registered User
    Join Date
    07-13-2009
    Location
    Kuala Lumpur
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Hide/Display selected columns

    One more thing, how do I put a stopper? Let's say if I want to stop checking until column AZ?

    Thanks
    Jennifer

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Hide/Display selected columns

    This will check the activecell's row to Column AZ
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    07-13-2009
    Location
    Kuala Lumpur
    MS-Off Ver
    Excel 2003
    Posts
    11

    Smile Re: Hide/Display selected columns

    It works perfectly!

    Thank you so much, RoyUK! I know I can depend on you guys!

    Jennifer

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Hide/Display selected columns

    Your post does not comply with Rule 9 of our Forum RULES. If you solve a problem yourself before anyone else has responded, please take a moment to describe your solution, chances are some other member will benefit. And please never edit a thread in which someone else has responded.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

    Don't just depend on us, study the code you are given & learn how it works so that you can help yourself

  13. #13
    Registered User
    Join Date
    07-13-2009
    Location
    Kuala Lumpur
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Hide/Display selected columns

    Thanks royUK, I will.

    Jennifer

+ Reply to Thread

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.6.0 RC 1