Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9276805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:56:20+00:00 2026-06-18T16:56:20+00:00

I read Google Script: Conditionally copy rows from one spreadsheet to another and could

  • 0

I read Google Script: Conditionally copy rows from one spreadsheet to another and could not make it work for me.

I need a script that will allow me to do the quoted text below. Please feel free to edit my spreadsheet to make a complete working script. I will keep the spreadsheet publicly available for anyone to copy the script for their own use. I really know nothing about script writing so I need it all spelled out. Sorry, I’m such a noob with all this, but this will help me learn.

https://docs.google.com/spreadsheet/ccc?key=0AoJdwy8V1ldHdFA5M1M1Wlp1NHZhcmxJOUZKVEU4X3c&usp=sharing

If Column B on sheet “All_Mileage” says “John” then I want that row to
be copy and pasted into Sheet “John” starting on row 3 and following.

If Column B on sheet “All_Mileage” says “Adam” then I want that row to
be copy and pasted into Sheet “Adam” starting on row 3 and following.

If Column B on sheet “All_Mileage” says “Mike” then I want that row to
be copy and pasted into Sheet “Mike” starting on row 3 and following.

I saw other scripts on here, but I couldn’t get them to work. Like I said I’m greener than a sapling when it come to code.

Thanks a ton!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:56:21+00:00Added an answer on June 18, 2026 at 4:56 pm

    C.Lang is right, this is not a place to get readymade scripts … but since this question is so common and has been aswered so often it took me a few minutes to write and test… so there it is :

    var ss=SpreadsheetApp.getActiveSpreadsheet();// some global variables
    var master = ss.getSheetByName('All_Mileage');
    var colWidth = master.getMaxColumns();
    
    
        function copyRowsOnCondition() {
          var data = master.getDataRange().getValues();
          for(n=2;n<data.length;++n){
            if(data[n][1].length<16){ // if not pre-filled with your text
            Logger.log(data[n][1])
             var dest = ss.getSheetByName(data[n][1].toString().replace(/ /g,''));//remove any spaces that could be included in the name so the name = sheetName for sure
             var destRange = dest.getRange(dest.getLastRow()+1,1);// the place to write
             master.getRange(n+1,1,1,colWidth).copyTo(destRange);the copy itself value & format
             }
          }// loop
        }
    

    EDIT : since I used the name value in MasterSheet to find destination sheet I thought it might be usefull to handle the case where the destination sheet doen’t exist by creating it using the same rule, ie. name = sheetName…

    The other issue was that there was no way to know which rows had been already copied… so I made a version that handles all that, copying only the rows that are manually selected (even in only a single column) and change the background color to tell that these rows have been processed. I also added a menu for a minimal comfort 😉

    (how to keep busy on a cold sunday afternoon 😉

    var ss=SpreadsheetApp.getActiveSpreadsheet();
    var master = ss.getSheetByName('All_Mileage');
    var colWidth = master.getLastColumn();// last used col in masterSheet
    var sheets = ss.getSheets();// number of sheets
    
    function onOpen() {
      var menuEntries = [ {name: "Copy selected Rows to sheets", functionName: "copyRowsOnConditionV2"},
    
                         ];
      ss.addMenu("Copy functions",menuEntries);// custom menu
    }
    function copyRowsOnConditionV2() {
      var sheetNames = [];// array of existing sheet names
      var sheets = ss.getSheets();// number of sheets
      for(s=0;s<sheets.length;++s){sheetNames.push(sheets[s].getName())};
      ss.getActiveSelection().setBackground('#ffffbb'); 
      var selectedfirstRow = ss.getActiveSelection().getRowIndex();
      var selectedHeigth = ss.getActiveSelection().getHeight()
      var selectedFullRange = master.getRange(selectedfirstRow,1,selectedHeigth,colWidth);
      var data = selectedFullRange.getValues();
      for(n=0;n<data.length;++n){
        if(data[n][1].length<16){
         if(sheetNames.toString().match(data[n][1].toString().replace(/ /g,''))!=data[n][1].toString().replace(/ /g,'')){// if no sheet exist with this name
         var newSheet = ss.insertSheet(data[n][1].toString().replace(/ /g,''),ss.getSheets().length);// then create it
         master.getRange(1,1,2,colWidth).copyTo(newSheet.getRange(1,1));// and copy the headers on 2 first rows, then continue as usual
         newSheet.getRange(1,1).setValue('Gas Mileage Log - '+data[n][1].toString().replace(/ /g,''));// set name in header
         SpreadsheetApp.flush();
         var sheets = ss.getSheets();// number of sheets
         var sheetNames = [];// update array of existing sheet names
         for(s=1;s<sheets.length;++s){sheetNames.push(sheets[s].getName())};
         Logger.log(sheetNames)
         };
         var dest = ss.getSheetByName(data[n][1].toString().replace(/ /g,''));//find the destination sheet
         Logger.log(data[n][1].toString().replace(/ /g,''))
         var destRange = dest.getRange(dest.getLastRow()+1,1);// define range
         master.getRange(selectedfirstRow+n,1,1,colWidth).copyTo(destRange);// and make copy below last row
         }
      }
    }
    

    Illustration below :

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read some of the basic Google Apps Script documentation/tutorials. I have not
I want to read some simple parameters from a Google Drive Spreadsheet using Google
I read the tutorial, https://developers.google.com/apps-script/articles/building-sites-app-part2 that uses spreadsheet service in Google sites. The code
So i curentlly run this script that i found from http://www.dcortesi.com/blog/2008/05/28/google-ajax-search-api-example-python-code/ import urllib import
I'm using a general Google Apps Script function to be able to read, prettify
i read your post on simple php script to retrieve google keyword search completion
I cannot seem to make this simple code work: <script type=text/javascript> $(document).ready(function(){ $.getJSON('http://maps.google.com/maps/api/geocode/json?address=cebu&sensor=false&region=ph', function(results)
I've this php script that loads google weather from google API. <?php //Weather Forecast
I wrote an apps-script attached to a Google spreadsheet, then transferred the ownership of
I have written some JavaScript code that will read from the Google Maps API

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.