Basically, I have an Excel file with *6* different areas.
I would like to enter data into 3 of the 6 areas, and have Excel only print the 3 areas when I click “print”
If I choose to enter data in 5 areas, I would like Excel to print 5 pages WITHOUT setting a print area every time.
Is it possible to have Excel only print certain areas IF there is data in there?
Thanks for any help you can provide!!!
Copyright © 2024 1QUIZZ.COM - All rights reserved.
Answers & Comments
Verified answer
Alt+F11, to go to vb editor, right click on the left side icon, then insert a module to the workbook, click the module, and on the right blank area add the code below
Sub printFilledPg()
prtarea = Array("$A$1:$G$24", "$A$25:$G$48", "$A$49:$G$72", "$A$73:$G$95", "$A$96:$G$119", "$A$120:$G$143") 'print area of corresponding sheet of below
celladd = Array("sheet1!$A$1", "sheet2!$A$1", "sheet3!$A$1", "sheet4!$A$1", "sheet5!$A$1", "sheet6!$A$1") 'cell with input will be printed, otherwise no
On Error Resume Next
For a = 0 To UBound( celladd)
aa = Split(celladd(a), "!")
Sheets( aa(0)).PageSetup.PrintArea = prtarea( a)
If Sheets( aa(0)).Range( aa(1)) <> "" Then Sheets( aa(0)).PrintOut
Next
End Sub
After adding the code, all you need to do is to add/change the 2nd and 3rd line of the code, the address of input cell where when data entered then page will be printed.
Alt+F8, click the name printFilledPg, click option button, set a shortcut, say ctrl+Shift+A, click ok button, then whenever you want to print, ctrl+shift+A to activate the macro.
This code not restrict page to 1 sheet, can be multi-sheets, can set more than 6 print area, just add the print area and target cell pair in line 1 & 2 of code
Please contact for more info
Yes, it can be done. However, it would have to be done in VBA as a macro and one would have to have the data on the *6* print area ranges.
Essentially, you would define the 6 data ranges, loop through the first range and test for data in any cell in the range. If found, set the print area and print the first area. Then test the second range the same way, set the print area and print the second area. And so on through all six ranges. If nothing is found in a given range, go on to the next range.
If you want to provide more specific data, I would be happy to write it.