function usingFunction(){
var sheetName = 'Sheet1'; //change according to your need
var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var selectedSheet = activeSpreadsheet.getSheetByName(sheetName);
var mySheet = selectedSheet;
var lastRow = mySheet.getLastRow();
var N = lastRow;
for (var i=2;i<=N;i++){// taking i=2 for headers change accordingly
var left ='LEFT($A'+i+',2)'; //Change "$A"according to your cell reference and "2" by the characters you need
mySheet.getRange(i, 2, 1, 1).setFormula(left);//sets formulas
//pasting it as values keep if needed
var getB =mySheet.getRange(i, 2, 1, 1);
var valueB ="B"+i;
getB.copyTo(mySheet.getRange(valueB), {contentsOnly:true});
}}
1条答案
按热度按时间2nbm6dog1#