Inserting blank row and summing coulumn

FrankMcNally

Board Regular
Joined
Nov 14, 2014
Messages
71
Hello again,

I work on various worksheets which import data into columns A:N with various amounts of rows

I need a macro to go the sheet and insert two lines whenever values in column D change.

The macro must also sum column N at each blank line.

The following inserts the blank line(s) when needed but sum the entire column N

Code:
Dim LastRow As Long    LastRow = Range("A5000").End(xlUp).Row
    Range("n" & LastRow + 1) = Application.WorksheetFunction.Sum(Range("n2:n" & LastRow))
    Columns("N:N").Select
    Columns("N:N").EntireColumn.AutoFit
    Range("N" & LastRow + 1).Select
    Selection.Font.Bold = True

My Spreadsheet looks like this:
REQ#Req TotalReq count DOProductCurrExchange rateSysDatePeriodINVAcct#DueDatePayeeLine1Amount
00000202100351507C0013076.18000000033540000000000100010000000000002015/10/0615160721520737001702015/09/09 John Doe$738.62
00000202100351507C0013076.18000000033540000000000100010000000000002015/10/0615160721520737001802015/09/09JanDoe$1,399.82
00000202100351507C0013076.18000000033540000000000100010000000000002015/10/0615160721520737002002015/09/09 Steve Smith$937.74
00000602100521507C00265000000015240000000000100010000000000002015/10/0615160734520599783702015/08/27O Sue Smith$65.00
7.1234$3,141.18

<tbody>
</tbody>

As you can see Column N is summed from N2:N6, but what I need is a sum of N2:N4 and one of N6

Anybody have any insight??
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I found this on another site:

Code:
[COLOR=#141414][FONT=open sans]EndRow = Cells([/FONT][/COLOR][COLOR=#141414][FONT=open sans]Rows.Count[/FONT][/COLOR][COLOR=#141414][FONT=open sans], "A").End(xlUp).Row[/FONT][/COLOR]

[COLOR=#141414][FONT=open sans]FirstRow = 1[/FONT][/COLOR]
[COLOR=#141414][FONT=open sans]RowCount = 1[/FONT][/COLOR]
[COLOR=#141414][FONT=open sans]Do While RowCount <= EndRow + 1[/FONT][/COLOR]

[COLOR=#141414][FONT=open sans]If IsEmpty(Cells(RowCount, "A")) Then[/FONT][/COLOR]

[COLOR=#141414][FONT=open sans]LastRow = RowCount - 1[/FONT][/COLOR]
[COLOR=#141414][FONT=open sans]Cells(RowCount, "A").FormulaR1C1 = _[/FONT][/COLOR]
[COLOR=#141414][FONT=open sans]"=SUM(R" & CStr(FirstRow) & "C1:R" & _[/FONT][/COLOR]
[COLOR=#141414][FONT=open sans]CStr(LastRow) & "C1)"[/FONT][/COLOR]

[COLOR=#141414][FONT=open sans]FirstRow = RowCount[/FONT][/COLOR]
[COLOR=#141414][FONT=open sans]RowCount = RowCount + 1[/FONT][/COLOR]

[COLOR=#141414][FONT=open sans]End If[/FONT][/COLOR]

[COLOR=#141414][FONT=open sans]RowCount = RowCount + 1[/FONT][/COLOR]
[COLOR=#141414][FONT=open sans]Loop[/FONT][/COLOR]

it kind of works, but

a: it's summing the incorrect column (A not N) and I'm not sure how to change the reference, I've change the two places where it states "A" to "N" but that just the reference cells to insert the data from what I can tell??

b: for the second sum, which should be $65 it's adding N4:N5 (well actually A4:A5, but see problem above) which includes the total for the previous group.

c: it's not putting in a blank line between the sum on line N4 and the next row of data.

I got this from:insert sum when first blank cell found | PC Review incase I'm supposed to cross-reference
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,074
Messages
6,128,653
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top