ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide Columns before Print problem (https://www.excelbanter.com/excel-programming/273339-hide-columns-before-print-problem.html)

Stuart[_5_]

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




All times are GMT +1. The time now is 06:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com