VBA code for adjusting print margins based on cell value

Metaleo

New Member
Joined
Apr 3, 2012
Messages
33
Hi All,

I have a 11 Page document that needs some, not all the pages printed at times. I have a toggle on each page for "Yes" to print or "No" not to print. Im new to VBA so forgive the poor excuse of a "code" Im about to post. I dont know of a better way to do this but I was hoping to use if/then combos to build a print area.


Sub testing()
'
' testing Macro
ActiveSheet.PageSetup.PrintArea = "A120:EF357" & _ '// Page 1 - 2
If ActiveSheet.Range("EK366").Value = "Yes" Then
Result = "A358:EF595" '// Page 3 -4
Else = "A477:EF595" '// Page 4
End If
If ActiveSheet.Range("EL603").Value = "Yes" Then
Result = "A596:EF714" '// Page 5
Else = ""
End If
If ActiveSheet.Range("EK722").Value = "Yes" Then
Result = "A715:EF833" '// Page 6
Else = ""
End If
If ActiveSheet.Range("EM842").Value = "Yes" Then
Result = "A834:EF952" '// Page 7
Else = ""
End If
If ActiveSheet.Range("EK960").Value = "Yes" Then
Result = "A953:EF1309" '// Page 8 -11
Else = "A1072:EF1309" '// Page 9 -11
End If








End Sub

Let me know what you guys think. Im not opposed to suggestions if you have a better way of working this out. Currently we print everything out and delete the extra pages.
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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