I want to copy values from one range to another sheet (in the same workbook) using Excel JavaScript, that is, taking some range values and pass them to another sheet.
The Excel Javascript API shows how to copy one range to another range in the same worksheet:
let sheet = context.workbook.worksheets.getItem("Sample");
// Copy everything from "A1:E1" into "G1" and the cells afterwards ("G1:K1").
sheet.getRange("G1").copyFrom("A1:E1");
await context.sync();
});
However I can't achieve to do it in another worksheet (of the same workbook).
This is the code that I'm using but it shows me some errors about using wrong parameters in the methods.
await Excel.run(async (context) => {
const captura = context.workbook.worksheets.getItem("Captura");
const historico = context.workbook.worksheets.getItem("Historico");
var rango = captura.getRange("A3:F5");
var i = historico.getUsedRange().getLastRow();
historico.getRange("A" + i).copyFrom(rango);
await context.sync();
});
}