+ Reply to Thread
Results 1 to 12 of 12

Code to insert a x number of rows and copy paste values

  1. #1
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Code to insert a x number of rows and copy paste values

    I have the following code that will insert a number of values based on another sheet number of cells. It finds the next blank cell in range(like Ctrl+Down) and inserts them. I want to paste the values in those new inserted rows, but I don't seem to manage that. Also would be possible to find and copy only the formulas from row above in these newly inserted rows(only the formulas, without the cells containing values. I have a mix of formulas and values in the cells above)

    Please Login or Register  to view this content.
    Click the * to say thanks.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,529

    Re: Code to insert a x number of rows and copy paste values

    And drumroll...

    Your sample file is where
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Code to insert a x number of rows and copy paste values

    Hi sintek, I've attached a sample. The part in yellow is the desired results after macro
    Attached Files Attached Files

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,529

    Re: Code to insert a x number of rows and copy paste values

    Formulas are in last 3 columns only...is this what you mean...
    By the way...calculation is currently set to manual...
    Please Login or Register  to view this content.
    Last edited by Sintek; 07-24-2020 at 04:04 AM.

  5. #5
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Code to insert a x number of rows and copy paste values

    The formula will always be in the last columns, but my last columns with formula will be dynamic. Using another macro, each time that one is run it will copy the range with formulas, will insert them again in the last column and paste the columns previously copied as values. Meaning that I cannot use the column title.

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,529

    Re: Code to insert a x number of rows and copy paste values

    EDIT...Now I get it...
    it must make use of the last 3 columns always...

    See amended code above...Will always use last 3 columns...
    Last edited by Sintek; 07-24-2020 at 04:05 AM.

  7. #7
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Code to insert a x number of rows and copy paste values

    The R-T columns in green will be moved in columns U-W when my other macro is run
    That means that they will be pasted as formats and formulas
    Then the macro will go back to R-T and paste them as values
    And this will happen all the time.E.g U-W will go to X-Z the second time macro is run and so on
    In this case, only the last 3 columns will contain formulas that needs to be pasted to the newly inserted rows
    Therefore, the macro that you help me with has to find the last 3 column (these will be dynamically moved) formulas and copy them down to the new inserted rows

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,529

    Re: Code to insert a x number of rows and copy paste values

    Therefore, the macro that you help me with has to find the last 3 column (these will be dynamically moved) formulas and copy them down to the new inserted rows
    As per post 6 the newly amended code does just that...

  9. #9
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Code to insert a x number of rows and copy paste values

    Hi again. The formula part works as intended. The copy/paste from J column presents an issue. The thing is that in J3 I have a title. Then in J5 and down, I have the data. Right now your macro copies the title from J3 3 times in my second sheet(I have title and 2 more values in column J). I tried using range J5 & lastrow but it doesn't do anything.
    Any ideea on how I may overcome this?

  10. #10
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,529

    Re: Code to insert a x number of rows and copy paste values

    Then in J5 and down
    So is the copy range always from J5:J & lastrow of column J?
    If so set rng to J5:J & lastrow then this should solve...or am i missing something else...
    Apologies for not quite understanding...Your sample file only had data from J5:J7
    and this snippet of your code did not reference J3 at all...
    Please Login or Register  to view this content.
    See attached file...


    i now see your problem...
    Please Login or Register  to view this content.
    should be...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Sintek; 07-24-2020 at 05:10 AM.

  11. #11
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Code to insert a x number of rows and copy paste values

    Absolutely perfect. Many thanks for your help and your fast replies. You are the man!

  12. #12
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,529

    Re: Code to insert a x number of rows and copy paste values

    .........................

    THANKS.gif

+ 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] how to insert empty rows based on column B cell values and paste above values with macro?
    By genetist in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-11-2018, 11:47 AM
  2. Insert set number of rows between data and copy and paste data above empty rows
    By Orionm45 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2017, 11:35 AM
  3. Copy values from single cell and paste to several number of rows
    By farel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-31-2017, 02:44 AM
  4. [SOLVED] VBA code to copy and paste a varying number of Rows
    By sx200n in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-10-2015, 08:57 AM
  5. Replies: 1
    Last Post: 10-05-2014, 12:28 PM
  6. Copy Paste the Missing Values in a Specified Cells and Insert the Rows into a Report
    By judeprem in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-30-2013, 01:46 PM
  7. Vba - find next empty column, insert column, copy paste values & copy paste formulas
    By DoodlesMama in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2012, 12:43 PM

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