Consulting

Results 1 to 19 of 19

Thread: Solved: Printing different columns

  1. #1
    VBAX Regular
    Joined
    Mar 2007
    Posts
    32
    Location

    Smile Solved: Printing different columns

    Hi Guys

    I have a spreadsheet with data in columns A, B, C, D, E, F and G, I want to print only columns B, E and F. How can I do this using VBA?

    Thank you

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Do you need to preserve spaces between the printed columns?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Mar 2007
    Posts
    32
    Location
    Thank you for your interest in try to help me mdmackillop, Answering your question..No, I don't want to preserve spaces between the printed columns

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    This might get you started:
    [VBA]Sub Macro1()
    Range("I10,A:A,C:C,D,G:G,H:H").EntireColumn.Hidden = True
    ActiveWindow.SelectedSheets.PrintPreview
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Regular
    Joined
    Mar 2007
    Posts
    32
    Location
    Thank you Lucas, the solution you gave me hide the columns that I don't want to print (nice trick) but it doesn't solve my problem, do you have other idea for solve my problem?

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    My solution would also be to hide the unwanted columns. You must have other secret problems you're not telling us about. If you care to let us in on them; we might find a solution.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I guess you will have to tell us what the problem is before we can help then......we're not mind readers so if this doesn't do what you want then you have to tell us why....

    but it doesn't solve my problem, do you have other idea for solve my problem?
    this doesn't tell me much
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    VBAX Regular
    Joined
    Mar 2007
    Posts
    32
    Location
    Please, I don't have any secret problem. I want to know how to print some selected columns out of a worksheet (with many columns of data) side by side on 1 page. Ex. Say I have data in columns from A to Z and I want to print on one page Columns c, M, R, S and W only. How do I do that?

  9. #9
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    When you say print do you mean print or copy to another sheet? What if we hide all columns except the ones you listed and then unhide them after print?

    Details required to assist....
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  10. #10
    VBAX Regular
    Joined
    Mar 2007
    Posts
    32
    Location
    Thanks Lucas, Maybe that can help. I don't want to copy I want to print I think the solution of hide and unhide will work, can you help me to do that? I'm completely new using VBA.

  11. #11
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Are the columns you wish to print static.....in other words will you always wish to print the same columns?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  12. #12
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Try this.....
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  13. #13
    VBAX Regular
    Joined
    Mar 2007
    Posts
    32
    Location
    Thanks Lucas, almost done...but I want to print different columns...Say the macro maybe ask me which columns I want to print, after that it'll print the columns selected for the Input

  14. #14
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Sure wish you had answered my question before I worked on this....have you done any research or work on this yourself? search the forum and web for inputbox. See what you can work out. I will check back later to see how your doing.

    There is also help for vba in the visual basic editor.

    I've shown you 2 possible methods of doing this so you should be able to make some progress on finishing it on your own..

    You can post any specific questions back in this thread..
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  15. #15
    VBAX Regular
    Joined
    Mar 2007
    Posts
    32
    Location
    Thank you Lucas for your time....so far I can hide the columns I don't want to print and after that print the rest, then unhide them....everything work fine but I cann't do the same when the spreadsheet is protected...it's possible run VBA code in protected spreadsheet?

  16. #16
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Try this:
    [VBA]Worksheets("MySheet").Unprotect Password:="drowssap"
    'your code here
    Worksheets("MySheet").Protect Password:="drowssap"[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  17. #17
    VBAX Regular
    Joined
    Mar 2007
    Posts
    32
    Location
    Thank you Lucas for your help

  18. #18
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Glad to help.....You can mark your thread solved using the thread tools at the top of the page when your ready. You can still post followup questions to this thread.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  19. #19
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Audax,
    I see it's taken 18 posts, and your developing question may not yet be fully answered. If you said at the outset, "I want to print out only the columns I enter in an InputBox, including possibly those on protected sheets", you would have had a complete solution within 2 posts. It's worth taking the time to compose your question. It saves us even more time in creating the solution.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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