+ Reply to Thread
Results 1 to 5 of 5

Insert row, copy formula, delete values

Hybrid View

inky Insert row, copy formula,... 06-14-2008, 04:23 AM
mudraker here's 1 way Sub... 06-14-2008, 04:37 AM
inky thanks mudraker - works... 06-14-2008, 04:55 AM
mudraker On Error Resume Next ... 06-14-2008, 07:19 AM
inky thanks for the explanation -... 06-14-2008, 11:58 PM
  1. #1
    Forum Contributor
    Join Date
    09-19-2007
    Posts
    115

    Insert row, copy formula, delete values

    i'm using the following macro to insert a row, copy formula from above then clear the values. yet when i place it on a row that has no values in cells (say A2 and B2) yet a formula in a cell (say A3) I get a 1004 error "no cells found".

    any suggestions on how to prevent this from occurring?

    Sub Copy_Formulas_Only()
        Dim row As Single
        row = ActiveCell.row
        Selection.EntireRow.Insert
        Rows(row - 1).Copy
        Rows(row).Select
        Selection.PasteSpecial Paste:=xlPasteFormulas
        Selection.SpecialCells(xlCellTypeConstants).ClearContents
        Application.CutCopyMode = False
    End Sub

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    here's 1 way

    Sub Copy_Formulas_Only()
        Dim row As Single
        row = ActiveCell.row
        Selection.EntireRow.Insert
        Rows(row - 1).Copy
        Rows(row).Select
       On Error Resume Next
        Selection.PasteSpecial Paste:=xlPasteFormulas
        Selection.SpecialCells(xlCellTypeConstants).ClearContents
       On Error GoTo 0
        Application.CutCopyMode = False
    End Sub
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Forum Contributor
    Join Date
    09-19-2007
    Posts
    115
    thanks mudraker - works great.

    so is the "On Error Resume Next" and "On Error GoTo 0" the VBA equivalent of ISERROR/ISNA etc in formula?

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    On Error Resume Next

    Specifies that when a run-time error occurs, control goes to the statement immediately following the statement where the error occurred where execution continues.

    On Error GoTo 0

    Disables any enabled error handler in the current procedure.

    e.g disables On Error Resume Next command

  5. #5
    Forum Contributor
    Join Date
    09-19-2007
    Posts
    115
    thanks for the explanation - helps my learning.

    now all i need is for the blues to get up over the pies and it's a great weekend!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1