Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel-insert cells and include formulas from above line

Status
Not open for further replies.

oggsta

Technical User
Jun 22, 2002
41
GB
I would like to insert cells and include formulas from above line, with one click of the button, as opposed to dragging each of the fromlas down from the above cell,any ideas on how to this would be appreciated.
 
Hi,

Try this...
Code:
Sub CopyLineAbove()
    Selection.EntireRow.Insert Shift:=xlDown
    With Selection
        .Offset(-1, 0).EntireRow.Copy
        .PasteSpecial _
            Paste:=xlPasteFormulas, _
            Operation:=xlNone, _
            SkipBlanks:=False, _
            Transpose:=False
    End With
End Sub
Hope this helps :)
Skip,
Skip@TheOfficeExperts.com
 
Yes this was very helpful, the only problem is that the values in the cell are copied over; is it possible to have blank cells with only the formulas copied in to the inserted row.

Regards
 
How's this...
Code:
Sub CopyLineAbove()
    Selection.EntireRow.Insert Shift:=xlDown
    With Selection
        lrow = .Offset(-1, 0).Row
        icol = ActiveSheet.UsedRange.Columns.Count
        For Each rng In Range(Cells(lrow, 1), Cells(lrow, icol))
            With rng
                If Left(rng.Formula, 1) = "=" Then
                    rng.Copy Destination:=rng.Offset(1, 0)
                End If
            End With
        Next
    End With
End Sub
Skip,
Skip@TheOfficeExperts.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top