Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Hide Columns before Print problem
The variable HideCols is used via a form, to establish if the
user wishes to hide any columns before printing. If so then an InputBox is used to gather those columns to be hidden, and they are then hidden. The following code is used to find LastCol and LastCol1: 'This code counts all columns, including hidden On Error Resume Next LastCol = Cells.Find("*", After:=.Cells(1), LookIn:=xlFormulas, _ LookAt:=xlWhole, SearchDirection:=xlPrevious, _ SearchOrder:=xlByColumns).Column 'Used with LastCol this code will go on to ignore any columns 'the user has chosen to hide 'MAKE SURE THEY ARE UNHIDDEN IF SAVED AS TRUE LastCol1 = Range(Cells(1, 1), Cells(1, LastCol)) _ .SpecialCells(xlVisible).Count On Error GoTo 0 In the following example, the user's ranges to print are A1:G56, A57:G112, A113:G168 etc. These ranges are established in an array (Pagevarr) BEFORE the column(s) if any chosen, are hidden. LastCol = 7, LastCol1 = 6. The user chose to hide Col D. If HideCols = False Then ColsToPrint = LastCol 'the original column count Else ColsToPrint = LastCol1 'omit the hidden columns End If 'Build an array of the ranges to be printed ReDim Printvarr(1 To 1) For j = 1 To UBound(Pagevarr) - 1 'nb: change the Resize value to suit the number of columns 'to be printed Set rng1 = Range(Pagevarr(j), Pagevarr(j + 1).Offset(-1, 0)) _ .Resize(, ColsToPrint) I think this is correct, so far? Later code runs, but when I test the range to be printed I find that it is correct for the rows, and correct in hiding Col D, but it is not showing Col G (the original last column) in printpreview.. The later code deals with pagesetup stuff, and I can't see any relevence there. Can anyone help, please? Regards. --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.505 / Virus Database: 302 - Release Date: 30/07/2003 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Want to Hide columns in spreadsheet but NOT hide data in chart. | Charts and Charting in Excel | |||
Print problem with columns | New Users to Excel | |||
How to show columns/cells in sheet but hide them in print? | Excel Discussion (Misc queries) | |||
Hide/Unhide columns using button on top over relevant columns | Excel Discussion (Misc queries) | |||
HIDE WHEN I PRINT | Excel Discussion (Misc queries) |