+ Reply to Thread
Results 1 to 7 of 7

Macro to paste formulas, but not values

  1. #1
    Registered User
    Join Date
    08-13-2013
    Location
    Mankato, Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    33

    Macro to paste formulas, but not values

    Hi,

    This is the macro that I have created:

    Sub AddRow(section As Integer)
    Dim A As Range, n As Long, F As Range: n = 11
    Do Until InStr(1, Range("A" & n + 2), "SECTION " & section + 1)
    n = n + 1: Loop
    Rows(CStr(n)).Insert Shift:=xlDown
    Rows(CStr(n - 1)).Copy
    Rows(CStr(n)).PasteSpecial Paste:=xlPasteFormats
    Application.CutCopyMode = False
    Range("G" & n - 1).AutoFill Destination:=Range("G" & n - 1 & ":G" & n)
    End Sub

    How do I get not only the format to paste, but also the formulas while leaving the inserted line blank- not copying the values from the line duplicated.

    Is there a way to add something to my macro to do this? Column F is actually the only column that has a formula in it, so that specifically is what I would like pasted with the inserted row.

    Let me know if I need to be more specific. Thanks for your help!

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Macro to paste formulas, but not values

    try
    Please Login or Register  to view this content.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    08-13-2013
    Location
    Mankato, Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Macro to paste formulas, but not values

    That seemed to work, but it also carries down the values that I had in the row above it. If possible I'd like it to clear the inserted row of values and only take the formula in Column F.

    Is there a way to manipulate the macro a little more to do this?

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Macro to paste formulas, but not values

    I think we might need to see your workbook. It might be the way you have the formulas.

  5. #5
    Registered User
    Join Date
    08-13-2013
    Location
    Mankato, Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Macro to paste formulas, but not values

    Excel Macro Help_3.xlsm

    Here is my file. I have assigned the "New Row" buttons to the macro's on the Sheet1.

    If you need more info, let me know!

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Macro to paste formulas, but not values

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-13-2013
    Location
    Mankato, Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Macro to paste formulas, but not values

    This now works, but only when I have the line that it is copying- inserting form- is filled out. When I try to add new row when the line above is empty then I get this error:

    Microsoft Visual Basic Application Error: 400

    Also, do you know of a way to make it unselect the line when the macro is done running? Currently it stays highlighted.

  8. #8
    Registered User
    Join Date
    08-13-2013
    Location
    Mankato, Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: Macro to paste formulas, but not values

    This now works, but only when I have the line that it is copying- inserting from- is filled out. When I try to add new row when the line above is empty then I get this error:

    Microsoft Visual Basic Application Error: 400

    Also, do you know of a way to make it unselect the line when the macro is done running? Currently it stays highlighted.

  9. #9
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655
    Where does it error out if the row is not completely filled out?

    To fix the selection issue just put Range("A1").select right before end sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. paste values only not formulas
    By tjjersey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2013, 01:12 PM
  2. Macro Copy Paste values not formulas lines above 0
    By bast0504 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-06-2013, 01:30 PM
  3. [SOLVED] Macro to paste formulas then paste values
    By deanstein in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-19-2013, 11:30 AM
  4. macro to copy cells with formulas and paste them as values
    By sammi8796 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2012, 08:00 PM
  5. Macro to Copy Paste Values and Formulas
    By thillis in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-19-2009, 11:55 AM

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