View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Stopher Stopher is offline
external usenet poster
 
Posts: 67
Default Finding last cell and insert line


Stopher wrote:
Added Tom's code for inserting formuals into this, might not look
pretty and prob abaly smarter ways of doing it but...

Sub AddFormulas()

Range("A1").Select

Do Until Cells(ActiveCell.Row + 1, 1) = "" And Cells(ActiveCell.Row +
2, 1) = ""

If ActiveCell = "" Then
Selection.EntireRow.Insert
ActiveCell.Range( _
"C1,F1:J1").FormulaR1C1 = "=Sum(R2C:R[-1]C)"
ActiveCell.Offset(2, 0).Select

Else
Cells(ActiveCell.Row + 1, 1).Select
End If
Loop
ActiveCell = ActiveCell.Offset(1, 0)
Selection.EntireRow.Insert
ActiveCell.Range( _
"C1,F1:J1").FormulaR1C1 = "=Sum(R2C:R[-1]C)"
ActiveCell.Offset(2, 0).Select

End Sub

Just change the starting cell ie Range("A1").select to suit and change
the formuals in

ActiveCell.Range( _
"C1,F1:J1").FormulaR1C1 = "=Sum(R2C:R[-1]C)"

to suit.

Regards

Stopher


If you wanted it just for the first contiguous block of data then:

Sub AddFormulas2()

Range("A1").Select

Range(Selection, Selection.End(xlDown)).Select

Cells(Selection.Item(Selection.Count), 1).Select

Selection.EntireRow.Insert
ActiveCell.Range( _
"C1,F1:J1").FormulaR1C1 = "=Sum(R2C:R[-1]C)"
ActiveCell.Offset(2, 0).Select

End Sub

Once again change you starting cell Range("A1").Select to suit

Stopher