PC Review


Reply
Thread Tools Rate Thread

Defining cells that shouldn't print

 
 
Steve
Guest
Posts: n/a
 
      17th Oct 2003
Hello,

Is it possible to define a cell range that should not appear on a print-out
of a worksheet?

Thanks in advance!

Steve


 
Reply With Quote
 
 
 
 
J.E. McGimpsey
Guest
Posts: n/a
 
      17th Oct 2003
One way (from

http://www.mcgimpsey.com/excel/noprintrange

):

You can hide rows or columns before printing.

If you have a range that doesn't consist of entire rows or columns
that you want to avoid printing, here's one way (it works for entire
rows and columns, too):

On each worksheet that you want to hide a range, select the range
(it can be non-contiguous) and give it a sheet level name of
"NoPrintRange" (one way: In the Name box at the left of the formula
bar, type the sheet name, then " !NoPrintRange ").

Put this in the ThisWorkbook code module: Ctrl-click (Mac) or
right-click (Windows, or Macs with 2-button mice) on the workbook
title bar, choose View Code , paste the following in the window that
opens, then click the XL icon on the toolbar to return to XL:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
'J.E. McGimpsey http://www.mcgimpsey.com/excel/noprintrange.html
Dim vFontArr As Variant
Dim oWkSht As Worksheet
Dim rNoPrintRange As Range
Dim rCell As Range
Dim rArea As Range
Dim i As Long
Dim bOldScreenUpdating As Boolean

Cancel = True
With Application
.EnableEvents = False
bOldScreenUpdating = .ScreenUpdating
.ScreenUpdating = False
End With
For Each oWkSht In ActiveWindow.SelectedSheets
On Error Resume Next
Set rNoPrintRange = oWkSht.Range("rNoPrintRange")
On Error GoTo 0
If Not rNoPrintRange Is Nothing Then
With rNoPrintRange
ReDim vFontArr(1 To .Count)
i = 1
For Each rArea In .Areas
For Each rCell In rArea
With rCell
vFontArr(i) = .Font.ColorIndex
If .Interior.ColorIndex = _
xlColorIndexNone Then
'white
.Font.Color = RGB(255, 255, 255)
Else
.Font.ColorIndex = _
.Interior.ColorIndex
End If
i = i + 1
End With
Next rCell
Next rArea
oWkSht.PrintOut
i = 1
For Each rArea In .Areas
For Each rCell In rArea
rCell.Font.ColorIndex = vFontArr(i)
i = i + 1
Next rCell
Next rArea
End With
Else
oWkSht.PrintOut
End If
Set rNoPrintRange = Nothing
Next oWkSht
With Application
.ScreenUpdating = bOldScreenUpdating
.EnableEvents = True
End With
End Sub

In article <YwRjb.27852$(E-Mail Removed)>,
"Steve" <(E-Mail Removed)> wrote:

> Hello,
>
> Is it possible to define a cell range that should not appear on a print-out
> of a worksheet?
>
> Thanks in advance!
>
> Steve
>
>

 
Reply With Quote
 
J.E. McGimpsey
Guest
Posts: n/a
 
      17th Oct 2003
Oops - I edited the macro to avoid linewrap problems and
inadvertently inserted a typo:

The line

Set rNoPrintRange = oWkSht.Range("rNoPrintRange")

should be

Set rNoPrintRange = oWkSht.Range("NoPrintRange")


In article
<jemcgimpsey-(E-Mail Removed)>,
"J.E. McGimpsey" <(E-Mail Removed)> wrote:

> One way (from
>
> http://www.mcgimpsey.com/excel/noprintrange
>

 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      17th Oct 2003
THanks!

"J.E. McGimpsey" <(E-Mail Removed)> wrote in message
news:jemcgimpsey-(E-Mail Removed)...
> One way (from
>
> http://www.mcgimpsey.com/excel/noprintrange
>
> ):
>
> You can hide rows or columns before printing.
>
> If you have a range that doesn't consist of entire rows or columns
> that you want to avoid printing, here's one way (it works for entire
> rows and columns, too):
>
> On each worksheet that you want to hide a range, select the range
> (it can be non-contiguous) and give it a sheet level name of
> "NoPrintRange" (one way: In the Name box at the left of the formula
> bar, type the sheet name, then " !NoPrintRange ").
>
> Put this in the ThisWorkbook code module: Ctrl-click (Mac) or
> right-click (Windows, or Macs with 2-button mice) on the workbook
> title bar, choose View Code , paste the following in the window that
> opens, then click the XL icon on the toolbar to return to XL:
>
> Private Sub Workbook_BeforePrint(Cancel As Boolean)
> 'J.E. McGimpsey http://www.mcgimpsey.com/excel/noprintrange.html
> Dim vFontArr As Variant
> Dim oWkSht As Worksheet
> Dim rNoPrintRange As Range
> Dim rCell As Range
> Dim rArea As Range
> Dim i As Long
> Dim bOldScreenUpdating As Boolean
>
> Cancel = True
> With Application
> .EnableEvents = False
> bOldScreenUpdating = .ScreenUpdating
> .ScreenUpdating = False
> End With
> For Each oWkSht In ActiveWindow.SelectedSheets
> On Error Resume Next
> Set rNoPrintRange = oWkSht.Range("rNoPrintRange")
> On Error GoTo 0
> If Not rNoPrintRange Is Nothing Then
> With rNoPrintRange
> ReDim vFontArr(1 To .Count)
> i = 1
> For Each rArea In .Areas
> For Each rCell In rArea
> With rCell
> vFontArr(i) = .Font.ColorIndex
> If .Interior.ColorIndex = _
> xlColorIndexNone Then
> 'white
> .Font.Color = RGB(255, 255, 255)
> Else
> .Font.ColorIndex = _
> .Interior.ColorIndex
> End If
> i = i + 1
> End With
> Next rCell
> Next rArea
> oWkSht.PrintOut
> i = 1
> For Each rArea In .Areas
> For Each rCell In rArea
> rCell.Font.ColorIndex = vFontArr(i)
> i = i + 1
> Next rCell
> Next rArea
> End With
> Else
> oWkSht.PrintOut
> End If
> Set rNoPrintRange = Nothing
> Next oWkSht
> With Application
> .ScreenUpdating = bOldScreenUpdating
> .EnableEvents = True
> End With
> End Sub
>
> In article <YwRjb.27852$(E-Mail Removed)>,
> "Steve" <(E-Mail Removed)> wrote:
>
> > Hello,
> >
> > Is it possible to define a cell range that should not appear on a

print-out
> > of a worksheet?
> >
> > Thanks in advance!
> >
> > Steve
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked cells return #Ref when they shouldn't! liiza Microsoft Excel Misc 2 1st Dec 2009 07:57 AM
Formulas appearing in empty cells when they shouldn't Paolo Microsoft Excel Programming 2 12th Jul 2008 09:07 AM
Cells Rounding up but shouldn't be myssieh Microsoft Excel Misc 1 3rd Mar 2008 05:07 PM
Picture pasting where it should but also in alot of cells it shouldn't DonFlak@gmail.com Microsoft Excel Programming 1 1st Nov 2007 01:37 AM
referenced cells displayed 0 when it shouldn't display anything drewmacher Microsoft Excel Misc 1 23rd Mar 2004 03:27 AM


Features
 

Advertising
 

Newsgroups
 


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