PDA

View Full Version : Solved: Printing different columns



Audax
04-04-2007, 01:54 PM
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

mdmackillop
04-04-2007, 02:01 PM
Do you need to preserve spaces between the printed columns?

Audax
04-05-2007, 06:03 AM
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

lucas
04-05-2007, 06:22 AM
This might get you started:
Sub Macro1()
Range("I10,A:A,C:C,D:D,G:G,H:H").EntireColumn.Hidden = True
ActiveWindow.SelectedSheets.PrintPreview
End Sub

Audax
04-05-2007, 07:53 AM
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?

mdmackillop
04-05-2007, 08:41 AM
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.

lucas
04-05-2007, 08:42 AM
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

Audax
04-05-2007, 09:25 AM
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?

lucas
04-05-2007, 09:32 AM
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....

Audax
04-05-2007, 09:43 AM
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.

lucas
04-05-2007, 09:48 AM
Are the columns you wish to print static.....in other words will you always wish to print the same columns?

lucas
04-05-2007, 10:26 AM
Try this.....

Audax
04-05-2007, 10:47 AM
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

lucas
04-05-2007, 10:54 AM
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..

Audax
04-05-2007, 12:17 PM
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?

lucas
04-05-2007, 12:29 PM
Try this:
Worksheets("MySheet").Unprotect Password:="drowssap"
'your code here
Worksheets("MySheet").Protect Password:="drowssap"

Audax
04-05-2007, 12:39 PM
Thank you Lucas for your help

lucas
04-05-2007, 12:43 PM
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.

mdmackillop
04-05-2007, 01:32 PM
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