Ask Your Question
0

Calc conditional page break macro

asked 2018-01-10 09:32:30 +0200

cpy gravatar image

So I have this question about how to add page break based on certain cell value. I have 3 ways how it can be done but I can't figure out how to do any of them.

  1. How to add page break on every selected cell? Let's say I select 100 specific rows and when I insert page break it only insert it to cursor position and not on every selected row.

  2. I could also insert it based on value, I have repeating counters going 1 2 3 4 5 1 2 3 1 2 3 4 5 6 so everytime there is 1 I need page break

  3. It also contains ascending numbers 1 1 1 1 1 2 2 2 3 3 3 3 3 3 this is what that counter above is doing so it is also possible to add page break on value change

All of those are rows of data going 1 1 - bunch of data 1 2 - bunch of data 1 3 - bunch of data 1 4 - bunch of data 2 1 - bunch of data (page break on this condition) 2 2 - bunch of data 2 3 - bunch of data

I can't add pagebreak when I filter all the 1 and i don't know how to make macro that adds pagebreak on every 1 in 2nd column or when value changes in first. All 3 solutions would give me same result.

Any help is appretiated, thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2018-01-10 14:32:42 +0200

librebel gravatar image

Hello @cpy,

To insert a pagebreak before every selected row, you could use the following macro:

Sub Calc_setPageBreaks()
REM Sets a Horizontal PageBreak before every Row in the current Selection.
    Dim oSheet As Object : oSheet = ThisComponent.CurrentController.ActiveSheet
    Dim oSelection As Object : oSelection = ThisComponent.getCurrentSelection()
    Dim oRangeAddress As Object : oRangeAddress = oSelection.getRangeAddress()
    Dim i As Integer
    For i = oRangeAddress.StartRow To oRangeAddress.EndRow
        oSheet.Rows(i).IsStartOfNewPage = True
    Next i
End Sub

HTH, lib

edit flag offensive delete link more

Comments

efffective, thanks

jonjiepante gravatar imagejonjiepante ( 2018-09-13 04:28:18 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-01-10 09:32:30 +0200

Seen: 175 times

Last updated: Jan 10 '18