vba for NOT PRINTING WHATS IN A CELL

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
821
Office Version
  1. 365
Platform
  1. Windows
I am trying to print a spreadsheet without it printing the text that is in a specific cell. I am currently using the macro below but would like this added if possible. the specific cell i do not want the text to print is P7.
Code:
Sub ArchiveIt()
Dim NR As Long
    NR = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row + 1
    
    Sheets("Sheet2").Range("A" & NR).Value = Sheets("BURN").Range("B5").Value
    Sheets("Sheet2").Range("B" & NR).Value = Sheets("BURN").Range("J4").Value
    Sheets("Sheet2").Range("C" & NR).Value = Sheets("BURN").Range("B7").Value
    Sheets("Sheet2").Range("D" & NR).Value = Sheets("BURN").Range("J5").Value
    Sheets("Sheet2").Range("E" & NR).Value = Sheets("BURN").Range("B6").Value
    Sheets("Sheet2").Range("F" & NR).Value = Sheets("BURN").Range("J6").Value
    Sheets("Sheet2").Range("G" & NR).Value = Sheets("BURN").Range("L16").Value
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
        Range("c11").Select
    Selection.ClearContents
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Found this a bit ago, haven't used it in a while but as I recall it worked...

Place this code in the ThisWorkbook module

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)

Application.EnableEvents = False
Cancel = True
A = Range("P7").NumberFormat
Range("P7").NumberFormat = ";;;"
Application.Dialogs(xlDialogPrint).Show
Range("P7").NumberFormat = A
Application.EnableEvents = True

End Sub
 
Upvote 0
it debugged when it got to Range("P7").NumberFormat = ";;;"
the text may be different in the cell from time to time
 
Upvote 0
it debugged when it got to Range("P7").NumberFormat = ";;;"
the text may be different in the cell from time to time
What happens if P7 has text in it? Maybe try this for both text or numeric content:
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)

Application.EnableEvents = False
Cancel = True
A = Range("P7").Font.Color
Range("P7").Font.Color = Range("P7").Interior.Color
Application.Dialogs(xlDialogPrint).Show
Range("P7").Font.Color = A
Application.EnableEvents = True

End Sub
 
Upvote 0
tried it in XL2010 and 2003 and working on this end with text and numbers. what error did it throw?
 
Upvote 0
let me make sure im putting the code in the correct location.
Does this go into the sheet code or the macro im running
 
Upvote 0
ok, I put it in there and it still prints it out. It is however a merged cell, would that matter??
 
Upvote 0
not if it was at the end of the merged range, maybe if it was the beginning cell of the range..............
 
Upvote 0

Forum statistics

Threads
1,213,550
Messages
6,114,265
Members
448,558
Latest member
aivin

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