Conditional Printing

joshlaf

New Member
Joined
Jul 10, 2018
Messages
3
Good Morning!

I have a bit of a question. Right now, I'm trying to make an inventory of the supply room which I will keep updated.

I'm just wondering if there's a way that excel can ignore if, for example, G7 is empty so therefore it will not print the whole row.




n902D39

n902D39.png


This is a very crude representation of what I'm trying to do, so I want to be able to print all the rows except the blank ones. I know I can sort by blank but I do not want to mess up the order of items. I've tried a few VBA codes, but none seem to do what I'm looking for.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hello and welcome.

Any reason you can't just filter out blanks and print that?
 
Upvote 0
I mean that is a possiblity, is there a macro in which I'd be able to do that? I'm just trying to minimize the steps.

If I could just run the macro, and it prints that would save me time. I found this VBA code in the search but it doesn't seem to be working.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Range("E").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="<>0", Operator:=xlAnd
End Sub
 
Upvote 0
Yes that's a little off.
this line will not work and selecting is rarely the best way of doing things:

Code:
[COLOR=#333333]Range("E").Select[/COLOR]

Is your table always the same range or is it dynamic. First issue is to ensure we always know what range the full data table covers (unless of course you have a named table)

Then you'd filter out the blanks, print and then show blanks again. Is this correct?
 
Upvote 0
This code will hide ALL blank rows print and then unhide them:

Code:
Sub HideAndPrint()
    With ActiveSheet
        .UsedRange.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
        .PrintOut
        .UsedRange.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = False
    End With
End Sub
 
Upvote 0
Thank you! I ended up getting there from rampant googling lol .

Sub FilterAndPrint()
Range("A1:E1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=5, Criteria1:=">=0"
Range("A1:E1").Select
Range("B:B").EntireColumn.Hidden = False
Range("C:C").EntireColumn.Hidden = True
Range("D:D").EntireColumn.Hidden = True
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Selection.AutoFilter
Range("B:B").EntireColumn.Hidden = True
Range("C:C").EntireColumn.Hidden = False
Range("D:D").EntireColumn.Hidden = False
End Sub
I'm assuming I can make it ignore rows as well?

Thanks so much
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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