How to copy the whole active column to a new column

Viewed 29

Is there any script that can copy the whole active column and paste just the values into a new column before the active one. For example:

i try this but im really bad and it doesn´t work

function Prueba() {
var spreadsheet = SpreadsheetApp.getActive(); spreadsheet.getActiveSheet().insertColumnsBefore(spreadsheet.getActiveRange().getColumn(), 1);
spreadsheet.getActiveRange().offset(0, 1, spreadsheet.getActiveRange().getNumRows(), 1).activate();
spreadsheet.getActiveRange().offset (0,-1, copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
 
};

but it

1 Answers

Copy Active Col to another Col

function cac() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getActiveSheet();
  const rg = sh.getActiveRange();
  const col = rg.getColumn();
  const vs = sh.getRange(1,col,sh.getLastRow()).getValues();
  sh.getRange(1,sh.getLastColumn() + 1,vs.length,vs[0].length).setValues(vs);
}
Related