+ Reply to Thread
Results 1 to 12 of 12

Insert rows with copying formula from above row

  1. #1
    Registered User
    Join Date
    10-05-2012
    Location
    Kazakhstan
    MS-Off Ver
    Excel 2010
    Posts
    12

    Question Insert rows with copying formula from above row

    Hi there!

    This is going to be my first post and probably the first macros-enabled excel sheet created by me, so I hope for your help!

    So I'm trying to do the following:

    The sheet consists of 13 columns.
    I want to protect it and then send to my colleagues. The main feature of it would be 2 buttons to insert the rows. The first button would insert all 13 columns below selected cell in a row and copy all formatting. Also cell g contains the formula which I'd like to be filled down (NOT COPIED, like I saw many times in the answers). So basically this is a recorded macro of what I'm trying to do:

    Please Login or Register  to view this content.
    The second button would do the following: it will insert the row below selected cell and merge cells from A to J with the cells from above rows (not all together, I need A72 to be merged with A 71, then B72 with B71, etc). Then two cells K and L would be just inserted and again cell M would be merged with above cell (like M2 with M1)
    So below is the VBA code that I want to be done by just clicking the button:

    Please Login or Register  to view this content.
    L&G, if somebody would help me with that I would probably be one of the happiest men in the world.

    I'm also attaching the sheet so you understand what I want exactly.
    sample.xlsm
    And to make me happy for the rest of my life - can you tell me how can I hide all columns starting from AA to the end and rows starting from 50?
    Last edited by masta-s; 10-07-2012 at 04:43 AM.

  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: Insert rows with copying formula from above row

    Hello masta-s,

    And to make me happy for the rest of my life
    To make the Forum Moderators happy, and before you can expect a reply to your problem, you will have to read and follow the Forum Rules. > Wrapping your Code <, for instance.
    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
    Registered User
    Join Date
    10-05-2012
    Location
    Kazakhstan
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Insert rows with copying formula from above row

    Quote Originally Posted by Winon View Post
    Hello masta-s,



    To make the Forum Moderators happy, and before you can expect a reply to your problem, you will have to read and follow the Forum Rules. > Wrapping your Code <, for instance.
    Winnon, thanks for help, hope this will work now :-)

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

    Re: Insert rows with copying formula from above row

    Hi masta-s,

    Merging Cells causes a myrid of problems. Would it be o.k. with you if we did not Merge any Cells?

  5. #5
    Registered User
    Join Date
    10-05-2012
    Location
    Kazakhstan
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Insert rows with copying formula from above row

    Quote Originally Posted by Winon View Post
    Hi masta-s,

    Merging Cells causes a myrid of problems. Would it be o.k. with you if we did not Merge any Cells?
    Winon,

    Sure it will work. I just have an excel sheet where they've managed to apply that, but unfortunately it's password protected as well as VBA code is pw protected too. But it looks so nice...

    Anyway, if there's a lot to do to make this work then sure at least pasting the rows without merging will do. Thanks in advance!

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Insert rows with copying formula from above row

    Hi, masta-s,

    maybe try these two modified versions of your macros:
    Please Login or Register  to view this content.
    I went from A to J on this, we could use an array to hold all Columns
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  7. #7
    Registered User
    Join Date
    10-05-2012
    Location
    Kazakhstan
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Insert rows with copying formula from above row

    Hi Holger,

    Thanks for your time spent to help me.
    The first code seems to be working, but it shifts the selected row down instead of adding the one below. But it works!

    As to the second one - that one just messes up the whole worksheet.

    I've attached the updated sheet with proposed codes (I've assigned them to the buttons) so if you have time - could you please check it?

    sample.xlsm

    Thanks in advance!

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

    Re: Insert rows with copying formula from above row

    Hi masta-s,

    Try the attached WorkBook.
    Attached Files Attached Files

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Insert rows with copying formula from above row

    Hi, Winon,

    instead of unprotecting the worksheet prior to use of the macro and thereafter I tend to protect the Worksheet on Activation with the parameter UserInterfaceOnly:=True which allows macros to be effective on that sheet while normal actions canīt take place. Behind the Sheet:

    Please Login or Register  to view this content.
    @masta-s:
    I strongly agree with Winon about Merged Cells - I should know how to handle them but try to avoid them whereever possible (my alternative is Center Across if needed or rely on Word for better "painting" abilities). Iīm sorry I messed the worksheet up - I didnīt test the code but that wasnīt at all expected to happen.

    Ciao,
    Holger

  10. #10
    Registered User
    Join Date
    10-05-2012
    Location
    Kazakhstan
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Insert rows with copying formula from above row

    Winon, thanks for time spent!

    Unfortunately the first macro also shifts the rows down, and I don't see any formula copied... So if you could use the sample I've attached in my last message and check what can be improved?

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

    Re: Insert rows with copying formula from above row

    @ HaHoBe,

    I agree with the Password UserInterFace suggestion. I was just so caught up with everything else and the Merge Cells, that I have overlooked it.

    However, I have changed your Merge code to Center Across Selection and it seems to be o.k., as long as the user remembers to select the Cell directly below the one to be "Stretched".

    @ masta-s,

    You can give this revised version a try as well.
    Attached Files Attached Files

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

    Re: Insert rows with copying formula from above row

    Here you go then,

    Also see the "Please consider" note at the bottom of this Post.
    Attached Files Attached Files
    Last edited by Winon; 10-07-2012 at 09:35 AM. Reason: Corrected Code

+ 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