Luis Eduardo
Luis Eduardo

Reputation: 47

PageSetup.PrintArea for multiple ranges that are separated

I have the following code that exports the selected range in the worksheet as .pdf file:

    'More coding above
    With Sheet7
        If (CheckBox1.Value = True And CheckBox2.Value = True) Then
            .PageSetup.PrintArea = "A8:M80"
        ElseIf (CheckBox1.Value = True And CheckBox2.Value = False) Then
            .PageSetup.PrintArea = "A8:M55"
        ElseIf (CheckBox1.Value = False And CheckBox2.Value = True) Then
            .PageSetup.PrintArea = "A8:M32, A56:M80"
        Else
            MsgBox 'At least one option must be selected!'
            Exit Sub
        End If
     End With
     'More coding below

However, when only CheckBox2 is checked, the file is generated selecting only the areas as set by If/Else, but still showing the A33:M55 gap between ranges.

Is there anyway I could suppress this gap? I want the code to print both ranges as if they were one.

I tried the Union method, but it gives me the same result.

Any help will be greatly appreciated!

Upvotes: 0

Views: 1158

Answers (1)

Rafał B.
Rafał B.

Reputation: 404

The simplest way is to hide unnecesarry rows if it's possible for a moment before print to PDF. In this way you should make sure after macro all rows are visible (additional you can use On Error GoTo and unhide just in case)

Upvotes: 1

Related Questions