PDA

View Full Version : Subtotal at each PageBreak



vloneboy
04-23-2019, 04:25 AM
Hello guys,

I really need your help with an VBA project I have to complete. The main goal is to convert an invoice from excel to word with the help of VBA.

My invoice starts at row 20 and has a widht of 8 columns, I want the subtotal of the amount in column 8 (column H) at each pagebreak. If it's possible it would be perfect when the subtotal is transfered to the next page.

When I run my code there are 22 rows with articles and prices (maybe that helps).

I hope you can help me with this issue (it bothers me for so long) and if you need further information to help, I will provide it to you.

Thank you

大灰狼1976
04-23-2019, 07:39 PM
Hi vloneboy!
Welcome to vbax forum.
It would be helpful if there was an example, The following code is for reference only.

Sub Test()
Dim i&, r&, st&, en&
st = 20
With Sheets(1)
For i = 1 To .HPageBreaks.Count
r = .HPageBreaks(i).Location.Row - 1
en = r - 1
.Rows(r).Insert
.Cells(r, 8) = "=sum(H" & st & ":H" & en & ")"
st = r + 1
Next i
End With
End Sub

akocak4
05-15-2019, 01:45 AM
I have a little revised the code from you ???1976.


I thought, this is what vloneboy wants.