Office Script.

HereToday

New Member
Joined
Aug 26, 2022
Messages
3
Office Version
  1. 365
Platform
  1. MacOS
Some code using office script to copy one row on an existing table (that only has one row in it!) to a new row on an existing table.


VBA Code:
function main(workbook: ExcelScript.Workbook) {
let CurrentWorksheet = workbook.getWorksheet("Audit File History");
let SourceTable = workbook.getTable("SampleTable");
let TargetTable = workbook.getTable("PracticeTable");
let SourceRange = SourceTable.getRangeBetweenHeaderAndTotal();
let SourceData = SourceRange.getValues();
//if I don't include this line, I get a two dimensional array?!
let FlatData = SourceData[0];

//Actual data array.
let PasteArray: [] = [];
PasteArray.push(FlatData);
console.log(FlatData);

//Dummy fixed data array, to compare with actual data array in console.
let FixedData: string [] = [];
FixedData.push("one","two","three");
console.log(FixedData);

/*
Result: I get two identical looking outputs in console.log.
However the error I get in Excel is this:
"[13, 17] Argument of type '(string | number | boolean)[]' is not assignable to parameter of type 'never'."
Log output(s):
(10) ["0D395D2E58", "Nation", 123456, 123456, "", "My Record", "Also", "Ran", "Yes", 123456]
(3) ["one", "two", "three"]
*/

TargetTable.addRow(-1, FlatData);
//The above line just errors, although from what I've read I need to insert new data as type array, to use the addrow command?
}

Anyway to the question? What is the right way to use office script to copy a row from one table to a new (last) row in another table?
The source table will only *ever* have one row in it, by design.
The target table will be an ever expanding table of rows.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top