excelvbaexport-to-pdf

Select some adjacent and non-adjacent column ranges and save to pdf as if they were all adjacent


I have a problem I need some help with. I have an excel sheet I need to export a report from to pdf. The first 2 adjacent columns should be in each report. I need to print 4 versions of the report containing 85 rows from Col A & B side by side together with one non-adjacent column to these (lets say Col F in one report version). I want col F to align side by side with cols A & B in the output pdf.

I've been playing about with range selection as in the following code. Sadly this gives me cols A & B side by side followed beneath by col F. If anyone has any pointers, I'd be grateful.

    Sub Export()
      Dim Rng As Range
      With ActiveSheet
        Set Rng = .Range("A1:B85, F1:F85")
        Rng.ExportAsFixedFormat Type:=xlTypePDF, fileName:="test.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
      End With
    End Sub

Solution

  • Please try to hide columns C:E before exporting.

    Sub Export()
        Dim Rng As Range
        With ActiveSheet
            Set Rng = .Range("A1:F85")
            With .Columns("C:E")
                .Hidden = True
                Rng.ExportAsFixedFormat Type:=xlTypePDF, Filename:="test.pdf", _
                    Quality:=xlQualityStandard, IncludeDocProperties:=True, _
                    IgnorePrintAreas:=False, OpenAfterPublish:=True
                .Hidden = False
            End With
        End With
    End Sub