Link to home
Start Free TrialLog in
Avatar of Matthew Nguyen
Matthew NguyenFlag for United States of America

asked on

Google Spreadsheet Script: Auto Iterate Next Row

I am a  newb when it comes to this stuff but I've been playing around Google App Script for a Google Spreadsheet and hoping someone can help/teach me how to customize code.

I found this code to populate data in my spreadsheet:
 
The spreadsheet I have is 6 columns wide (A-F) and what I want to do is customize the code so that as I enter information in a new row in column A, columns B-F will auto-populate.  I know I can just drag the formulas down, but it would be a "nice to have" to just have to auto populate.

I know Google App Script has a command called "getLastRow"  that can facilitate this problem, I'm just not sure how to set it up.

Thanks for the help.
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In the absence of any update from you, taking it a step further and showing for example a way of posting the formulae then:

Chris
var sht = SpreadsheetApp.getActiveSheet();
  var rw = sht.getLastRow();
  var str

  sht.getRange(rw, 2).setValue (2);
  sht.getRange(rw, 3).setValue (3);
  str = 'B' + rw + ':C' + rw;
  sht.getRange(rw, 4).setFormula ('=sum(' + str + ')');
  str = 'B' + rw + ',C' + rw;
  sht.getRange(rw, 5).setFormula ('multiply(' + str + ')');

Open in new window

Avatar of Matthew Nguyen

ASKER

Sorry, I was out all weekend, let me give this a go and see if I can get it to work, thanks for the help.

Matt
Thanks