Forum Discussion
Jeff_Hunt
Aug 15, 2023Copper Contributor
Need a script to find the last cell-copy, paste as value, then format as text on another sheet.
Here is a greatly simplified version of a script I am trying to run: In this example I have it going to a single column sheet that will work fine. It may work better (I need this for a Pow...
- Aug 16, 2023
Perhaps like
function main(workbook: ExcelScript.Workbook) { const value = workbook .getWorksheet("Sheet1") .getUsedRange() .getLastCell() .getValue() .toString() const targetCell = workbook .getWorksheet("Sheet2") .getUsedRange() .getLastCell() .getOffsetRange(1, 0) targetCell .setNumberFormats([["@"]]) targetCell .setValue(value) }
SergeiBaklan
Aug 16, 2023Diamond Contributor
In simplest case that is
function main(workbook: ExcelScript.Workbook) {
const value = workbook
.getWorksheet("Sheet1")
.getUsedRange()
.getLastCell()
.getValue()
.toString()
workbook
.getWorksheet("Sheet2")
.getUsedRange()
.getLastCell()
.getOffsetRange(1,0)
.setValue(value)
}
if you mean to copy last cell from column E in Sheet1 to the bottom of values in column A in Sheet2.
Or you mean to copy all values from first sheet into second one at once?
- Jeff_HuntAug 16, 2023Copper Contributor
This first one is preferred (and almost accomplishes everything). Is there a way to add that the final formatting be text? It is coming out "general" and I need it to read as text for some other functionality.
- SergeiBaklanAug 16, 2023Diamond Contributor
Perhaps like
function main(workbook: ExcelScript.Workbook) { const value = workbook .getWorksheet("Sheet1") .getUsedRange() .getLastCell() .getValue() .toString() const targetCell = workbook .getWorksheet("Sheet2") .getUsedRange() .getLastCell() .getOffsetRange(1, 0) targetCell .setNumberFormats([["@"]]) targetCell .setValue(value) }
- Jeff_HuntAug 16, 2023Copper ContributorPERFECT - many thanks!