VBA to turn off cell fill when printing then turn back on

ydilday

New Member
Joined
Apr 22, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I am looking for a VBA to turn off cell fill when I go to print a spread sheet and then turn the fill back on after the printing is done.
Essentially I want the spread sheet to print in black and white but have the company logo print in color.
The cells are color filled with conditional formatting.
Thank you.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
The fact that the formatting is conditional ramps up the difficulty. How many conditional formatting rules do you have?

The way I would approach this is to update the rules to include a "flag" cell. Let's say we use Z99 for that purpose. If I have a rule like this:
Excel Formula:
=A1>100
I would update it to
Excel Formula:
=AND(Z99, A1>100)

Then Z99 can be used like a switch to turn on and off the conditional formatting. (You could even use a checkbox linked to Z99 to do it.)

A macro can be installed to automatically make this cell FALSE before printing. However, there is no AfterPrint event to automatically turn it back on. You would have to use a macro to do the printing rather than File > Print.
 
Upvote 0
The fact that the formatting is conditional ramps up the difficulty. How many conditional formatting rules do you have?

The way I would approach this is to update the rules to include a "flag" cell. Let's say we use Z99 for that purpose. If I have a rule like this:
Excel Formula:
=A1>100
I would update it to
Excel Formula:
=AND(Z99, A1>100)

Then Z99 can be used like a switch to turn on and off the conditional formatting. (You could even use a checkbox linked to Z99 to do it.)

A macro can be installed to automatically make this cell FALSE before printing. However, there is no AfterPrint event to automatically turn it back on. You would have to use a macro to do the printing rather than File > Print.
I am fine with removing the conditional formatting and just using regular cell fill if that makes it easier.
 
Upvote 0
The fact that the formatting is conditional ramps up the difficulty. How many conditional formatting rules do you have?

The way I would approach this is to update the rules to include a "flag" cell. Let's say we use Z99 for that purpose. If I have a rule like this:
Excel Formula:
=A1>100
I would update it to
Excel Formula:
=AND(Z99, A1>100)

Then Z99 can be used like a switch to turn on and off the conditional formatting. (You could even use a checkbox linked to Z99 to do it.)

A macro can be installed to automatically make this cell FALSE before printing. However, there is no AfterPrint event to automatically turn it back on. You would have to use a macro to do the printing rather than File > Print.
Jeff, I like that approach! Very clever way to approach it!
 
Upvote 0
I am fine with removing the conditional formatting and just using regular cell fill if that makes it easier.
Another way would be to create a copy of the sheet, remove all fill and conditional formatting, then print the copy and delete it. Note that it will remove all conditional formatting, including fonts and number formats.
VBA Code:
Public Sub PrintNoFill()

   Dim PrintCopy As Worksheet
   Dim SourceWS As Worksheet
   
   Set SourceWS = ActiveSheet
   
   SourceWS.Copy after:=SourceWS
   Set PrintCopy = Worksheets(SourceWS.Index + 1)
   
   With PrintCopy.UsedRange.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
   End With
   
   PrintCopy.Cells.FormatConditions.Delete

   PrintCopy.PrintOut
   
   Application.DisplayAlerts = False
   PrintCopy.Delete
   Application.DisplayAlerts = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top