+ Reply to Thread
Results 1 to 31 of 31

Macro for button, insert row above button, copy formulas and formatting from row above

  1. #1
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Macro for button, insert row above button, copy formulas and formatting from row above

    Help. This should be pretty simple, but apparently isn't?

    I have a row with content, formulas, and conditional formatting.
    I have a button below that row.
    I want to press the button, insert a row above the button, but copy down the row above and clear contents, but keep formulas and formatting.

    HELP!!!

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Hello TheBullND,

    Welcome to the Forum.

    Please see if you could use the attached sample Workbook.

    Regards
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Forum Contributor BeachRock's Avatar
    Join Date
    11-01-2011
    Location
    Oregon, United States
    MS-Off Ver
    Excel 2016
    Posts
    403

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Hi TheBullND,

    I have some code you might be able to use. This also has the ability to insert a specified number of rows that are copied, basically repeating the copy and insert as many times as you specify. B1 is the cell containing the number of copies to produce in the example below.

    Just change the ranges:

    Range("A12:AW12").Copy
    Range("A15:AW15").Select

    To the ranges where you need to copy from and where to insert the copied range.

    Please Login or Register  to view this content.
    -------------
    Tony

  4. #4
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Thank you. Not exactly what I want it to do, but close. I was hoping for code to insert a row above my button without the "prompt" and then also to clear the contents. Thoughts?

  5. #5
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    My first reply was to Winon. Thank you BeachRock, let me try...

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Hello TheBullND,

    Thank you for the feedback.

    I would need to see what your sheet layout is like and where you have Formulas, since you cannot ClearContents with clearing out formulas as well. We will have to reference specific Cells to retain Formulae.

    Please upload a sample Workbook.

    Regards

  7. #7
    Forum Contributor BeachRock's Avatar
    Join Date
    11-01-2011
    Location
    Oregon, United States
    MS-Off Ver
    Excel 2016
    Posts
    403

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    To additionaly cleaar the contents of the range copied, change Range("A12:AW12").Select to the range you are copying.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    And the reason I want it in reference to the "button" is because when you press the "button" and it inserts the row above the button and below the previous row, the button will shift down a row.
    Similar to this:
    Please Login or Register  to view this content.
    But its not copying down the previous row, etc.
    Last edited by TheBullND; 10-27-2013 at 01:25 AM.

  9. #9
    Forum Contributor BeachRock's Avatar
    Join Date
    11-01-2011
    Location
    Oregon, United States
    MS-Off Ver
    Excel 2016
    Posts
    403

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    I think you might want to work with Winon for the clearing of contents as my suggestion will clear the formulae too.

  10. #10
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Actually...getting close with this simple one:
    Please Login or Register  to view this content.
    ...But instead of being based on the "ActiveCell", I want it based on the button location which changes with each inserted row. Then i'll have to deal with clearing content as well.

    Thoughts?
    Last edited by TheBullND; 10-27-2013 at 01:25 AM.

  11. #11
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    OK...found this that is simple and inserts a row above the button perfectly.

    Please Login or Register  to view this content.
    Now I just need it to copy down formulas from the row above the newly inserted row.
    Last edited by TheBullND; 10-27-2013 at 01:24 AM.

  12. #12
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Here is my simple spreadsheet...attached.

    I'd like the "Insert Row" button to insert a row above the button, copy down all of the formulas and conditional formatting from the row above the button, and then clear the content.

    Doable?

  13. #13
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Winon, spreadsheet posted (I think).

  14. #14
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Hi TheBullND,

    Please follow the Forum Rules by Wrapping any Code you may Post.

    Return to your posts, Click on Edit>highlight the Code>Click on #, in the options immediately above in the window.

    Thank you.

  15. #15
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Gotcha. Done. Thanks. (newbie)

  16. #16
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Hi TheBullND,

    Thank you for for your prompt response regarding wrapping of Code.

    It is always better to upload a sample Workbook. Now I fully understand your requirements.

    I have also corrected your Dividing Formula so as not to return an error.

    Please try the Workbook now.

    Regards

  17. #17
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Winon, thank you. That's what I'm looking for, but with one tweak. When it inserts the row, it is also inserting another "Insert Row" button along with the row, that I don't want. Is it copying the row with the button instead of the row above the button? Can you Copy selected row minus 1, then insert and clear contents keeping formulas?

  18. #18
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Sorry TheBullND, but it is not doing what you say it does, on my side. I have tried it in different versions of Excel, without a problem.

    Are we on the same "Page" here, or have you changed anything in the Code of my sample Workbook?

  19. #19
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Hmmm...I am on Excel 2010. I will upload your file again, code unchanged, but after I press the "Insert Row" button and you should see the button replicated for each inserted row. Thoughts?

  20. #20
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    I am stumped. Please try this one in .xlsm format.

  21. #21
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Hmmm, I can't get it to NOT replicate/duplicate the "insert row" button when pressed.

  22. #22
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Hello TheBullND,

    Please replace your Code with the Code below, and let me know if it now works for you.

    Please Login or Register  to view this content.
    Regards

  23. #23
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Bingo!!! I think we have a winner. Thank you VERY much!!!

  24. #24
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Now I am finding that it doesn't work if I copy that whole section down and paste it again. It resorts back to duplicating the button along with the row. I'm thinking I just need to make a new button and new macro for each "copied" down section and assign the new macro to the new button, updating the macro button # each time in the code? I think that will work.

  25. #25
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Hello TheBullND,

    I shall try to obtain a newer version of Excel 2007, and see how best we can solve your issue. Never had this problem before, it may have to do with something very simple.

    Regards

  26. #26
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Thank you very much. I am on Excel 2010, so I'm not sure if somethere with the new version is messing up the typical macro.

  27. #27
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Hello TheBullND,

    Taking a long shot here, but please try the Code below;

    Please Login or Register  to view this content.

  28. #28
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    This code is nice because it looks like it isn't referencing an actual button number, but unfortunately it resorted back to replicating the button. Ugh.

  29. #29
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Hello TheBullND,

    Thank you for the feedback.

    O.K. then, let's try it this way:

    Please Login or Register  to view this content.

  30. #30
    Registered User
    Join Date
    10-26-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Hot digggity. I think we have a winner. Works when copied down too.

  31. #31
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro for button, insert row above button, copy formulas and formatting from row above

    Hello TheBullND,


    You are welcome.


    I am glad that we could finally sort this one out.

    If you are satisfied with the solution I had given you, then please mark your Thread as Solved.

    You may also Click on the Star to the far left, at the bottom of this Post, to Add Reputation.

    Thank you,

    Regards

+ 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. [SOLVED] Button to insert new row, clear data and keep formulas
    By dragosnb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2013, 07:52 AM
  2. copy/insert button
    By RorschachDK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2013, 03:01 AM
  3. Command Button using VBA, to insert a row with formulas below
    By AlexKost in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-14-2013, 11:50 PM
  4. Comand button to insert new row and copy formulas only
    By ir_eddie in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-06-2012, 06:14 AM
  5. Insert rows and formulas above Button
    By alexandruc in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 03-17-2010, 02:52 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