+ Reply to Thread
Results 1 to 7 of 7

Code assistance needed

  1. #1
    JimMay
    Guest

    Code assistance needed

    I've just come across this code in my archives, and it isn't
    Working. It might be full of errors, but can someone assist is
    Getting it on its feet?
    Thanks in Advance.
    Jim


    Sub PrintSubTotalInFooter()
    Dim lrow As Long
    Dim numhpb As Long
    Dim LPage As Long
    Dim i As Integer
    Dim STRng As Range
    Application.EnableEvents = False
    ' The PageSetUp Print Range has already been set to Range A5:F149
    Set STRng = Application.InputBox("Highlight the Range of Amts to be
    Subtotaled", Type:=8)
    rrows = Range(ActiveSheet.PageSetup.PrintTitleRows).Rows.Count
    With ActiveSheet
    .PageSetup.RightFooter = ""
    numhpb = .HPageBreaks.Count
    LPage = numhpb + 1
    For i = 1 To numhpb
    .PageSetup.RightFooter = "Sub-total = " &
    Format(WorksheetFunction.Sum _
    (Range(STRng(1).Address, STRng(.HPageBreaks(i).Location.Row
    - (1 + rrows)).Address)), "0,000.00")
    On Error GoTo ErrorHandler
    .PrintPreview i, i
    Next i
    .PageSetup.RightFooter = "The-total = " &
    Format(WorksheetFunction.Sum _
    (STRng), "0,000.00")
    On Error GoTo ErrorHandler
    .PrintPreview LPage, LPage
    End With
    ErrorHandler:
    Application.EnableEvents = True
    End Sub


  2. #2
    Haldun Alay
    Guest

    Re: Code assistance needed

    Code is working. But before running macro, you need to do few things.

    1. Set the print area
    2. Set the rows those will be repeated top of the pages.
    3. Run the macro

    --

    Haldun Alay

  3. #3
    JimMay
    Guest

    Re: Code assistance needed

    Haldun; Thanks for looking at this and offering your comments.
    I did as you said, yet when I run Step 3, I get nothing...
    <<What I'd expect to be a Print-Preview>>.


    "Haldun Alay" <[email protected]> wrote in message
    news:#[email protected]:

    > Code is working. But before running macro, you need to do few things.
    >
    > 1. Set the print area
    > 2. Set the rows those will be repeated top of the pages.
    > 3. Run the macro
    >
    > --
    >
    > Haldun Alay



  4. #4
    Haldun Alay
    Guest

    Re: Code assistance needed

    You need to replace printpreview with printout and use this macro instead of standard print command.

    Because of page header and footer are static it is printing the pages one by one.

    Code follows.

    Sub PrintSubTotalInFooter()
    Dim lrow As Long
    Dim numhpb As Long
    Dim LPage As Long
    Dim i As Integer
    Dim STRng As Range
    Application.EnableEvents = False
    ' The PageSetUp Print Range has already been set to Range A5:F149
    Set STRng = Application.InputBox( _
    "Highlight the Range of Amts to be Subtotaled ", Type:=8)
    rrows = Range(ActiveSheet.PageSetup.PrintTitleRows).Rows.Count
    With ActiveSheet
    .PageSetup.RightFooter = ""
    numhpb = .HPageBreaks.Count
    LPage = numhpb + 1
    For i = 1 To numhpb
    .PageSetup.RightFooter = "Sub-total = " & Format( _
    WorksheetFunction.Sum(Range(STRng(1).Address, _
    STRng(.HPageBreaks(i).Location.Row - (1 + rrows)).Address)), _
    "0,000.00")
    On Error GoTo ErrorHandler
    .PrintOut i, i
    Next i
    .PageSetup.RightFooter = "The-total = " & Format(WorksheetFunction.Sum( _
    STRng), "0,000.00")
    On Error GoTo ErrorHandler
    .PrintOut LPage, LPage
    End With
    ErrorHandler:
    Application.EnableEvents = True
    End Sub




    --
    Haldun Alay


  5. #5
    Haldun Alay
    Guest

    Re: Code assistance needed

    You need to replace printpreview with printout and use this macro instead of standard print command.

    Because of page header and footer are static it is printing the pages one by one.

    Code follows.

    Sub PrintSubTotalInFooter()
    Dim lrow As Long
    Dim numhpb As Long
    Dim LPage As Long
    Dim i As Integer
    Dim STRng As Range
    Application.EnableEvents = False
    ' The PageSetUp Print Range has already been set to Range A5:F149
    Set STRng = Application.InputBox( _
    "Highlight the Range of Amts to be Subtotaled ", Type:=8)
    rrows = Range(ActiveSheet.PageSetup.PrintTitleRows).Rows.Count
    With ActiveSheet
    .PageSetup.RightFooter = ""
    numhpb = .HPageBreaks.Count
    LPage = numhpb + 1
    For i = 1 To numhpb
    .PageSetup.RightFooter = "Sub-total = " & Format( _
    WorksheetFunction.Sum(Range(STRng(1).Address, _
    STRng(.HPageBreaks(i).Location.Row - (1 + rrows)).Address)), _
    "0,000.00")
    On Error GoTo ErrorHandler
    .PrintOut i, i
    Next i
    .PageSetup.RightFooter = "The-total = " & Format(WorksheetFunction.Sum( _
    STRng), "0,000.00")
    On Error GoTo ErrorHandler
    .PrintOut LPage, LPage
    End With
    ErrorHandler:
    Application.EnableEvents = True
    End Sub




    --
    Haldun Alay


  6. #6
    JimMay
    Guest

    Re: Code assistance needed

    So there's no way to Preview this before actually Printing it?
    Appreciate you help;
    Jim


    "Haldun Alay" <[email protected]> wrote in message
    news:OS7m#[email protected]:

    > You need to replace printpreview with printout and use this macro instead of standard print command.
    >
    > Because of page header and footer are static it is printing the pages one by one.
    >
    > Code follows.
    >
    > Sub PrintSubTotalInFooter()
    > Dim lrow As Long
    > Dim numhpb As Long
    > Dim LPage As Long
    > Dim i As Integer
    > Dim STRng As Range
    > Application.EnableEvents = False
    > ' The PageSetUp Print Range has already been set to Range A5:F149
    > Set STRng = Application.InputBox( _
    > "Highlight the Range of Amts to be Subtotaled ", Type:=8)
    > rrows = Range(ActiveSheet.PageSetup.PrintTitleRows).Rows.Count
    > With ActiveSheet
    > .PageSetup.RightFooter = ""
    > numhpb = .HPageBreaks.Count
    > LPage = numhpb + 1
    > For i = 1 To numhpb
    > .PageSetup.RightFooter = "Sub-total = " & Format( _
    > WorksheetFunction.Sum(Range(STRng(1).Address, _
    > STRng(.HPageBreaks(i).Location.Row - (1 + rrows)).Address)), _
    > "0,000.00")
    > On Error GoTo ErrorHandler
    > .PrintOut i, i
    > Next i
    > .PageSetup.RightFooter = "The-total = " & Format(WorksheetFunction.Sum( _
    > STRng), "0,000.00")
    > On Error GoTo ErrorHandler
    > .PrintOut LPage, LPage
    > End With
    > ErrorHandler:
    > Application.EnableEvents = True
    > End Sub
    >
    >
    >
    >
    > --
    > Haldun Alay
    >
    >



  7. #7
    paul
    Guest

    Re: Code assistance needed

    might be on the wrong track but will you get a print preview with enable
    events=false?
    --
    paul
    [email protected]
    remove nospam for email addy!



    "JimMay" wrote:

    > So there's no way to Preview this before actually Printing it?
    > Appreciate you help;
    > Jim
    >
    >
    > "Haldun Alay" <[email protected]> wrote in message
    > news:OS7m#[email protected]:
    >
    > > You need to replace printpreview with printout and use this macro instead of standard print command.
    > >
    > > Because of page header and footer are static it is printing the pages one by one.
    > >
    > > Code follows.
    > >
    > > Sub PrintSubTotalInFooter()
    > > Dim lrow As Long
    > > Dim numhpb As Long
    > > Dim LPage As Long
    > > Dim i As Integer
    > > Dim STRng As Range
    > > Application.EnableEvents = False
    > > ' The PageSetUp Print Range has already been set to Range A5:F149
    > > Set STRng = Application.InputBox( _
    > > "Highlight the Range of Amts to be Subtotaled ", Type:=8)
    > > rrows = Range(ActiveSheet.PageSetup.PrintTitleRows).Rows.Count
    > > With ActiveSheet
    > > .PageSetup.RightFooter = ""
    > > numhpb = .HPageBreaks.Count
    > > LPage = numhpb + 1
    > > For i = 1 To numhpb
    > > .PageSetup.RightFooter = "Sub-total = " & Format( _
    > > WorksheetFunction.Sum(Range(STRng(1).Address, _
    > > STRng(.HPageBreaks(i).Location.Row - (1 + rrows)).Address)), _
    > > "0,000.00")
    > > On Error GoTo ErrorHandler
    > > .PrintOut i, i
    > > Next i
    > > .PageSetup.RightFooter = "The-total = " & Format(WorksheetFunction.Sum( _
    > > STRng), "0,000.00")
    > > On Error GoTo ErrorHandler
    > > .PrintOut LPage, LPage
    > > End With
    > > ErrorHandler:
    > > Application.EnableEvents = True
    > > End Sub
    > >
    > >
    > >
    > >
    > > --
    > > Haldun Alay
    > >
    > >

    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1