vba for NOT PRINTING WHATS IN A CELL

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
794
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
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

matttclark

Board Regular
Joined
Jan 13, 2011
Messages
100
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
 

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
794
it debugged when it got to Range("P7").NumberFormat = ";;;"
the text may be different in the cell from time to time
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,389
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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
 

matttclark

Board Regular
Joined
Jan 13, 2011
Messages
100

ADVERTISEMENT

tried it in XL2010 and 2003 and working on this end with text and numbers. what error did it throw?
 

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
794
let me make sure im putting the code in the correct location.
Does this go into the sheet code or the macro im running
 

matttclark

Board Regular
Joined
Jan 13, 2011
Messages
100

ADVERTISEMENT

neither, use ThisWorkbook.
 

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
794
ok, I put it in there and it still prints it out. It is however a merged cell, would that matter??
 

matttclark

Board Regular
Joined
Jan 13, 2011
Messages
100
not if it was at the end of the merged range, maybe if it was the beginning cell of the range..............
 

Watch MrExcel Video

Forum statistics

Threads
1,123,402
Messages
5,601,475
Members
414,452
Latest member
Dannysamworth

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
Top