Consulting

Results 1 to 5 of 5

Thread: Include Multiple column groups on every page?

  1. #1

    Include Multiple column groups on every page?

    Hello

    I have an Excel template with data that is creating individual worksheets using some VB code. The template contains a section of code that specifies the formatting for each newly created worksheet (landscape, legal paper, page breaks, etc).

    Is there a way that I can use VBA to modify the Page Setup to include columns A, B, H and I on every page.

    Such that Page 1 [Columns A-N], Page 2 [A,B,H,I,O-X], Page 3 [A,B,H,I,Y-AI] and so on.

    Hopefully someone can point me in the right direction.

    Thanks

  2. #2
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Can you post your code?
    Peace of mind is found in some of the strangest places.

  3. #3
    It's a pretty massive amount of code overall. In the setup for any new worksheet, here's how I'm defining the Page Setup properties...

    newSht.PageSetup.PaperSize = xlPaperLegal
    newSht.PageSetup.Orientation = xlLandscape
    newSht.PageSetup.Order = xlOverThenDown
    newSht.PageSetup.PrintTitleRows = "$1:$6"
    newSht.PageSetup.PrintTitleColumns = "$A:$B"
    newSht.VPageBreaks.Add Range("O1")
    newSht.VPageBreaks.Add Range("Y1")
    newSht.VPageBreaks.Add Range("AJ1")
    newSht.VPageBreaks.Add Range("AV1")

    Once the page is setup the rest is just a data dump.

    I was trying before to include more than one section of columns, but that doesn't work...

    newSht.PageSetup.PrintTitleColumns = "$A:$B"
    newSht.PageSetup.PrintTitleColumns = "$H:$I"

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    It appears PrintTitleColumns must be contiguous. Why not copy/insert for printing, then delete when finished?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Also, try tidying up using With statements
    [vba]
    With newsht
    With .PageSetup
    .PaperSize = xlPaperLegal
    .Orientation = xlLandscape
    .Order = xlOverThenDown
    .PrintTitleRows = "$1:$6"
    .PrintTitleColumns = Range(Columns("$A:$B"), Columns("$H:$I")).Address
    End With
    With .VPageBreaks
    .Add Range("O1")
    .Add Range("Y1")
    .Add Range("AJ1")
    .Add Range("AV1")
    End With
    End With

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •