Inserting Rows Automatically... ?
Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Inserting Rows Automatically... ?

  1. #11
    Board Regular
    Join Date
    Jan 2019
    Posts
    57
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Inserting Rows Automatically... ?

    Quote Originally Posted by lrobbo314 View Post
    Seems like you're doing it correctly. Can you post more sample data so I can try to see what is happening?
    I'll try - hopefully screenshots will make it clearer... also, I said 25 rows in total before - sorry, it should be 26!



    This is the list I receive - there are about 100 "groups" of between 1 to 25 all in a long list... column C is how they are numbered etc





    And this is the format it needs to be in - all the groups separated consistently with 25 rows, plus 1 extra row marked in orange etc... so there is always 25 rows between each orange row





    When I run your code - it seems to work on the first group fine, but then carries on inserting rows afterwards, so pushing the rest of the data continuously down...


    Thank you again!

  2. #12
    Board Regular lrobbo314's Avatar
    Join Date
    Jul 2008
    Location
    California
    Posts
    2,381
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Inserting Rows Automatically... ?

    Of course. Easy fix. Just move from bottom to top instead of top to bottom. Here's the updated code. Worked on bigger data set over here.

    Code:
    function InsertRowsFX() {
      var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
      var lastRow = sheet.getLastRow();
      
      for(var i=lastRow; i >=3; i--) {
        if(sheet.getRange(i, 3).getValue()==1) {
          sheet.insertRowsBefore(i, 26 - sheet.getRange(i, 3).getValue());
        }
      }
    }
    To add code to a workbook. Hit Alt+F11. Hit Alt+I+M to insert new module. Then paste code.
    Array formulas must be entered by hitting Ctrl+Shift+Enter.

    We can't solve problems by using the same kind of thinking we used when we created them.

    Imagination is more important than knowledge.

  3. #13
    Board Regular
    Join Date
    Jan 2019
    Posts
    57
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Inserting Rows Automatically... ?

    Awesome! Thank you so much!

    But there's another problem now lol - this error message keeps coming up ... "Exceeded maximum execution time"

    Is there any way to increase the execution time or speed up the script?

    Or can I re-run the script somehow so it carries on from where it left off?
    Last edited by Aitch; Sep 13th, 2019 at 05:47 PM.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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