Google Apps Script to replace formula with text in the current row











up vote
0
down vote

favorite












I'm trying to write a script in google sheets so that if I change a cell in column F, it will copy and paste values on the same row in columns b:e. I'd appreciate any help.



I have a google sheet where operators log events. They type in a reference number in column a and it looks up corresponding data (from another tab) and displays it in columns b-e. Then they add data like their name, the current time, etc in columns F-M. I'm trying to write a script so that when I change column F it copies the results from the formulas in columns b-e in the current row and pastes them back in place as values.



The reason is two-fold, one removing the formulas and pasting values improves performance and two if someone changed the lookup data the row becomes corrupted.



I found the following script that inserts a timestamp - seems like minor modifications would work but I haven't been able to figure it out. (thank you to the author of this)



//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK = 1;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,11];
// Sheet you are working on
var SHEETNAME = 'ReceivingLog'

function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//checks that we're on the correct sheet.
if( sheet.getSheetName() == SHEETNAME ) {
var selectedCell = ss.getActiveCell();
//checks the column to ensure it is on the one we want to cause the date to appear.
if( selectedCell.getColumn() == COLUMNTOCHECK) {
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
dateTimeCell.setValue(new Date());
}
}
}









share|improve this question






















  • I partially figured it out:
    – Roger
    Nov 9 at 21:49















up vote
0
down vote

favorite












I'm trying to write a script in google sheets so that if I change a cell in column F, it will copy and paste values on the same row in columns b:e. I'd appreciate any help.



I have a google sheet where operators log events. They type in a reference number in column a and it looks up corresponding data (from another tab) and displays it in columns b-e. Then they add data like their name, the current time, etc in columns F-M. I'm trying to write a script so that when I change column F it copies the results from the formulas in columns b-e in the current row and pastes them back in place as values.



The reason is two-fold, one removing the formulas and pasting values improves performance and two if someone changed the lookup data the row becomes corrupted.



I found the following script that inserts a timestamp - seems like minor modifications would work but I haven't been able to figure it out. (thank you to the author of this)



//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK = 1;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,11];
// Sheet you are working on
var SHEETNAME = 'ReceivingLog'

function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//checks that we're on the correct sheet.
if( sheet.getSheetName() == SHEETNAME ) {
var selectedCell = ss.getActiveCell();
//checks the column to ensure it is on the one we want to cause the date to appear.
if( selectedCell.getColumn() == COLUMNTOCHECK) {
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
dateTimeCell.setValue(new Date());
}
}
}









share|improve this question






















  • I partially figured it out:
    – Roger
    Nov 9 at 21:49













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to write a script in google sheets so that if I change a cell in column F, it will copy and paste values on the same row in columns b:e. I'd appreciate any help.



I have a google sheet where operators log events. They type in a reference number in column a and it looks up corresponding data (from another tab) and displays it in columns b-e. Then they add data like their name, the current time, etc in columns F-M. I'm trying to write a script so that when I change column F it copies the results from the formulas in columns b-e in the current row and pastes them back in place as values.



The reason is two-fold, one removing the formulas and pasting values improves performance and two if someone changed the lookup data the row becomes corrupted.



I found the following script that inserts a timestamp - seems like minor modifications would work but I haven't been able to figure it out. (thank you to the author of this)



//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK = 1;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,11];
// Sheet you are working on
var SHEETNAME = 'ReceivingLog'

function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//checks that we're on the correct sheet.
if( sheet.getSheetName() == SHEETNAME ) {
var selectedCell = ss.getActiveCell();
//checks the column to ensure it is on the one we want to cause the date to appear.
if( selectedCell.getColumn() == COLUMNTOCHECK) {
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
dateTimeCell.setValue(new Date());
}
}
}









share|improve this question













I'm trying to write a script in google sheets so that if I change a cell in column F, it will copy and paste values on the same row in columns b:e. I'd appreciate any help.



I have a google sheet where operators log events. They type in a reference number in column a and it looks up corresponding data (from another tab) and displays it in columns b-e. Then they add data like their name, the current time, etc in columns F-M. I'm trying to write a script so that when I change column F it copies the results from the formulas in columns b-e in the current row and pastes them back in place as values.



The reason is two-fold, one removing the formulas and pasting values improves performance and two if someone changed the lookup data the row becomes corrupted.



I found the following script that inserts a timestamp - seems like minor modifications would work but I haven't been able to figure it out. (thank you to the author of this)



//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK = 1;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,11];
// Sheet you are working on
var SHEETNAME = 'ReceivingLog'

function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//checks that we're on the correct sheet.
if( sheet.getSheetName() == SHEETNAME ) {
var selectedCell = ss.getActiveCell();
//checks the column to ensure it is on the one we want to cause the date to appear.
if( selectedCell.getColumn() == COLUMNTOCHECK) {
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
dateTimeCell.setValue(new Date());
}
}
}






google-apps-script






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 19:11









Roger

41




41












  • I partially figured it out:
    – Roger
    Nov 9 at 21:49


















  • I partially figured it out:
    – Roger
    Nov 9 at 21:49
















I partially figured it out:
– Roger
Nov 9 at 21:49




I partially figured it out:
– Roger
Nov 9 at 21:49












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Partially solved: The second function (below) works as a stand-alone to copy paste values, but it doesn't like the two functions strung together like this. Looking for help on how to have two scripts function together.



//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK = 1;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,11];
// Sheet you are working on
var SHEETNAME = 'ReceivingLog'

function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//checks that we're on the correct sheet.
if( sheet.getSheetName() == SHEETNAME ) {
var selectedCell = ss.getActiveCell();
//checks the column to ensure it is on the one we want to cause the date to appear.
if( selectedCell.getColumn() == COLUMNTOCHECK) {
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
dateTimeCell.setValue(new Date());
}
}
}

//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK2 = 2;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION2 = [0,-1];

// Sheet you are working on
var SHEETNAME2 = 'PurchaseOrders'

function onEdit2(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//checks that we're on the correct sheet.
if( sheet.getSheetName() == SHEETNAME2 ) {
var selectedCell = ss.getActiveCell();
//checks the column to ensure it is on the one we want to cause the date to appear.
if( selectedCell.getColumn() == COLUMNTOCHECK2) {
var dateTimeCell = selectedCell.offset(DATETIMELOCATION2[0],DATETIMELOCATION2[1]);
var data = dateTimeCell.getValues()
dateTimeCell.setValue(data) , {contentsOnly: true};
}
}
}





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53214605%2fgoogle-apps-script-to-replace-formula-with-text-in-the-current-row%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Partially solved: The second function (below) works as a stand-alone to copy paste values, but it doesn't like the two functions strung together like this. Looking for help on how to have two scripts function together.



    //CORE VARIABLES
    // The column you want to check if something is entered.
    var COLUMNTOCHECK = 1;
    // Where you want the date time stamp offset from the input location. [row, column]
    var DATETIMELOCATION = [0,11];
    // Sheet you are working on
    var SHEETNAME = 'ReceivingLog'

    function onEdit(e) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getActiveSheet();
    //checks that we're on the correct sheet.
    if( sheet.getSheetName() == SHEETNAME ) {
    var selectedCell = ss.getActiveCell();
    //checks the column to ensure it is on the one we want to cause the date to appear.
    if( selectedCell.getColumn() == COLUMNTOCHECK) {
    var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
    dateTimeCell.setValue(new Date());
    }
    }
    }

    //CORE VARIABLES
    // The column you want to check if something is entered.
    var COLUMNTOCHECK2 = 2;
    // Where you want the date time stamp offset from the input location. [row, column]
    var DATETIMELOCATION2 = [0,-1];

    // Sheet you are working on
    var SHEETNAME2 = 'PurchaseOrders'

    function onEdit2(e) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getActiveSheet();
    //checks that we're on the correct sheet.
    if( sheet.getSheetName() == SHEETNAME2 ) {
    var selectedCell = ss.getActiveCell();
    //checks the column to ensure it is on the one we want to cause the date to appear.
    if( selectedCell.getColumn() == COLUMNTOCHECK2) {
    var dateTimeCell = selectedCell.offset(DATETIMELOCATION2[0],DATETIMELOCATION2[1]);
    var data = dateTimeCell.getValues()
    dateTimeCell.setValue(data) , {contentsOnly: true};
    }
    }
    }





    share|improve this answer

























      up vote
      0
      down vote













      Partially solved: The second function (below) works as a stand-alone to copy paste values, but it doesn't like the two functions strung together like this. Looking for help on how to have two scripts function together.



      //CORE VARIABLES
      // The column you want to check if something is entered.
      var COLUMNTOCHECK = 1;
      // Where you want the date time stamp offset from the input location. [row, column]
      var DATETIMELOCATION = [0,11];
      // Sheet you are working on
      var SHEETNAME = 'ReceivingLog'

      function onEdit(e) {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getActiveSheet();
      //checks that we're on the correct sheet.
      if( sheet.getSheetName() == SHEETNAME ) {
      var selectedCell = ss.getActiveCell();
      //checks the column to ensure it is on the one we want to cause the date to appear.
      if( selectedCell.getColumn() == COLUMNTOCHECK) {
      var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
      dateTimeCell.setValue(new Date());
      }
      }
      }

      //CORE VARIABLES
      // The column you want to check if something is entered.
      var COLUMNTOCHECK2 = 2;
      // Where you want the date time stamp offset from the input location. [row, column]
      var DATETIMELOCATION2 = [0,-1];

      // Sheet you are working on
      var SHEETNAME2 = 'PurchaseOrders'

      function onEdit2(e) {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getActiveSheet();
      //checks that we're on the correct sheet.
      if( sheet.getSheetName() == SHEETNAME2 ) {
      var selectedCell = ss.getActiveCell();
      //checks the column to ensure it is on the one we want to cause the date to appear.
      if( selectedCell.getColumn() == COLUMNTOCHECK2) {
      var dateTimeCell = selectedCell.offset(DATETIMELOCATION2[0],DATETIMELOCATION2[1]);
      var data = dateTimeCell.getValues()
      dateTimeCell.setValue(data) , {contentsOnly: true};
      }
      }
      }





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Partially solved: The second function (below) works as a stand-alone to copy paste values, but it doesn't like the two functions strung together like this. Looking for help on how to have two scripts function together.



        //CORE VARIABLES
        // The column you want to check if something is entered.
        var COLUMNTOCHECK = 1;
        // Where you want the date time stamp offset from the input location. [row, column]
        var DATETIMELOCATION = [0,11];
        // Sheet you are working on
        var SHEETNAME = 'ReceivingLog'

        function onEdit(e) {
        var ss = SpreadsheetApp.getActiveSpreadsheet();
        var sheet = ss.getActiveSheet();
        //checks that we're on the correct sheet.
        if( sheet.getSheetName() == SHEETNAME ) {
        var selectedCell = ss.getActiveCell();
        //checks the column to ensure it is on the one we want to cause the date to appear.
        if( selectedCell.getColumn() == COLUMNTOCHECK) {
        var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
        dateTimeCell.setValue(new Date());
        }
        }
        }

        //CORE VARIABLES
        // The column you want to check if something is entered.
        var COLUMNTOCHECK2 = 2;
        // Where you want the date time stamp offset from the input location. [row, column]
        var DATETIMELOCATION2 = [0,-1];

        // Sheet you are working on
        var SHEETNAME2 = 'PurchaseOrders'

        function onEdit2(e) {
        var ss = SpreadsheetApp.getActiveSpreadsheet();
        var sheet = ss.getActiveSheet();
        //checks that we're on the correct sheet.
        if( sheet.getSheetName() == SHEETNAME2 ) {
        var selectedCell = ss.getActiveCell();
        //checks the column to ensure it is on the one we want to cause the date to appear.
        if( selectedCell.getColumn() == COLUMNTOCHECK2) {
        var dateTimeCell = selectedCell.offset(DATETIMELOCATION2[0],DATETIMELOCATION2[1]);
        var data = dateTimeCell.getValues()
        dateTimeCell.setValue(data) , {contentsOnly: true};
        }
        }
        }





        share|improve this answer












        Partially solved: The second function (below) works as a stand-alone to copy paste values, but it doesn't like the two functions strung together like this. Looking for help on how to have two scripts function together.



        //CORE VARIABLES
        // The column you want to check if something is entered.
        var COLUMNTOCHECK = 1;
        // Where you want the date time stamp offset from the input location. [row, column]
        var DATETIMELOCATION = [0,11];
        // Sheet you are working on
        var SHEETNAME = 'ReceivingLog'

        function onEdit(e) {
        var ss = SpreadsheetApp.getActiveSpreadsheet();
        var sheet = ss.getActiveSheet();
        //checks that we're on the correct sheet.
        if( sheet.getSheetName() == SHEETNAME ) {
        var selectedCell = ss.getActiveCell();
        //checks the column to ensure it is on the one we want to cause the date to appear.
        if( selectedCell.getColumn() == COLUMNTOCHECK) {
        var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
        dateTimeCell.setValue(new Date());
        }
        }
        }

        //CORE VARIABLES
        // The column you want to check if something is entered.
        var COLUMNTOCHECK2 = 2;
        // Where you want the date time stamp offset from the input location. [row, column]
        var DATETIMELOCATION2 = [0,-1];

        // Sheet you are working on
        var SHEETNAME2 = 'PurchaseOrders'

        function onEdit2(e) {
        var ss = SpreadsheetApp.getActiveSpreadsheet();
        var sheet = ss.getActiveSheet();
        //checks that we're on the correct sheet.
        if( sheet.getSheetName() == SHEETNAME2 ) {
        var selectedCell = ss.getActiveCell();
        //checks the column to ensure it is on the one we want to cause the date to appear.
        if( selectedCell.getColumn() == COLUMNTOCHECK2) {
        var dateTimeCell = selectedCell.offset(DATETIMELOCATION2[0],DATETIMELOCATION2[1]);
        var data = dateTimeCell.getValues()
        dateTimeCell.setValue(data) , {contentsOnly: true};
        }
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 21:53









        Roger

        41




        41






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53214605%2fgoogle-apps-script-to-replace-formula-with-text-in-the-current-row%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Verwaltungsgliederung Dänemarks

            Liste der Kulturdenkmale in Wilsdruff