View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default how do I add a row when the second last one is used

Can't tell from your post which column is used for totals and how the data
gets entered but for example assume column A

Enter this formula in A2

=SUM(A1:INDEX(A:A,ROW()-1))

Paste this event code into your worksheet then start entering numbers in A1.

A row will be inserted and the SUM range will expand to include the new row.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo enditall
Application.EnableEvents = False
If Target.Cells.Column = 1 Then
n = Target.Row
If Range("A" & n).Value < "" Then
Range("A" & n).Offset(1, 0).EntireRow.Insert
End If
End If
enditall:
Application.EnableEvents = True
End Sub

Right-click on your sheet tab and "View Code". Copy/paste the code into
that module. Edit to suit then Alt + q to return to the Excel window.


Gord Dibben MS Excel MVP

On Sun, 7 Sep 2008 16:39:01 -0700, Scott
wrote:

I am setting up a Invoice and I want to be able to add a new row whenever the
second last one is used. ( the last one contains the totals )

ie: if row 22 is used then it creates a new row (using the same type of
format as before)
I know this is a easy task but I am still a beginner trying to lealn this
program I am not sure of how to do this task.

Thanks in advance