Inserting Rows Automatically... ?

Aitch

Board Regular
Joined
Jan 27, 2019
Messages
81
Office Version
2010
Platform
Windows
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!
 

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

lrobbo314

Well-known Member
Joined
Jul 14, 2008
Messages
2,761
Office Version
365, 2019, 2016
Platform
Windows
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());
    }
  }
}
 

Aitch

Board Regular
Joined
Jan 27, 2019
Messages
81
Office Version
2010
Platform
Windows
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:

Aitch

Board Regular
Joined
Jan 27, 2019
Messages
81
Office Version
2010
Platform
Windows
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());
    }
  }
}
Is there no fix or work-around for this?



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?
 

Watch MrExcel Video

Forum statistics

Threads
1,102,202
Messages
5,485,326
Members
407,496
Latest member
PttrsnMrgn

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top