+ Reply to Thread
Results 1 to 8 of 8

macro to selectively hide columns for printing

  1. #1
    Registered User
    Join Date
    12-15-2005
    Posts
    42

    Angry macro to selectively hide columns for printing

    Hi,
    I have a worksheet range A1:O92.
    I want the user to be able to run a macro that will allow them to select which columns are to be printed (or not printed).
    I always want all of the rows to be printed.
    I am assuming the best way to do this is to "hide" the columns that will not be printed.
    Can someone help me with code that will allow the macro to ask the user to individually select columns: A thru O to be hidden then press "Enter"?
    Once I have the worksheet set up with the proper columns shown I can finish the macro for printing out the selected columns.
    Thank you for any input!

  2. #2
    Forum Contributor
    Join Date
    05-04-2012
    Location
    Stamford,Connecticut,USA
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: macro to selectively hide columns for printing

    So why can't the user click on the columns and manually hit hide then print? How much time and effort are your really saving?

  3. #3
    Registered User
    Join Date
    12-15-2005
    Posts
    42

    Re: macro to selectively hide columns for printing

    Perfectly good question ... but there are other issues with the worksheet and the users are not familiar with excel at all.
    My current worksheet is formatted (my another macro) such that when you click any cell (or column heading) it highlights the whole row (or all of the columns) ... which means if you click on a column to hide it, it will highlight all of the columns and they will all disappear. I do have a command button to turn this feature off but I didn't want the user to have to make that decision.
    My macro would also incorporate defeating this "highlighting the whole row" (worksheet event) before it asks the user which columns to hide.
    Thanks again!

  4. #4
    Forum Contributor
    Join Date
    05-04-2012
    Location
    Stamford,Connecticut,USA
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: macro to selectively hide columns for printing

    The following code will hide the columns where the user has click while holding the Control Key. The last line re-opens the hidden columns so the process can be repeated; you will have to stick your printing code after the For Next loop and before the las line. Otherwise you may want to add check boxes for column selection. Either way the user must do "something".
    Please Login or Register  to view this content.

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: macro to selectively hide columns for printing

    Hi elevdown
    I prefer to use a UserForm for this type of User Interface...see attached.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: macro to selectively hide columns for printing

    Hi elevdown,

    Here's another option:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  7. #7
    Registered User
    Join Date
    12-15-2005
    Posts
    42

    Re: macro to selectively hide columns for printing

    Thanks for the replies ... these are 3 great ideas.
    RaulRodrigues - this was the original direction I was headed - thanks.
    jaslake - I never thought of this (not familiar at all with userforms but I think that is a great idea - I will have to learn more about that - thanks to you also!
    xladept - this works very well also - I should be able to incorporate this into my macro for printing desired columns - thanks very much to all!

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: macro to selectively hide columns for printing

    Hi elevdown,

    Thanks for the response - glad it's worked out!

+ 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