Office Scripts

greenhillchris

New Member
Joined
Mar 5, 2022
Messages
18
Office Version
  1. 365
Hi ,

My below Office Script should add an extra 50 rows to a table at row 27.

However I am getting the following error message Line 7: Table addRows: The argument is invalid or missing or has an incorrect format.

This appears to becoing from numRow, where am I going wrong with this code?

1.function main(workbook: ExcelScript.Workbook) {
2.let selectedSheet = workbook.getActiveWorksheet();
3. let table = workbook.getTable("Table1");
4. let startRow = 27;
5. let numRow = 50;
6.
7.table.addRows(startRow,numRow);
8.}

Thanks
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
A function can't nake physical adjustments to a worksheet, only return a result.
Maybe this way
VBA Code:
Sub ResizeTable()
Dim x As Long, z As String  
 With ActiveSheet.ListObjects("Table1")
       x = 27'Current table rows count 
       z = 1 'Current table start cell     
  .Resize Range(z, Cells(x + 50).Address) 'Resize table   
End With
End Sub
 
Upvote 0
A function can't nake physical adjustments to a worksheet,
Michael, the OP is using Office Script (the code used in Excel online) not VBA, the use of Function is correct in Office Script (VBA doesn't work in Excel online).

I'm afraid that I can't advise the Op as I don't dabble in Office Script
 
Upvote 0
LOL...Obviously, neither do I....Thx for the heads up !!
 
Upvote 0
Hi ,

My below Office Script should add an extra 50 rows to a table at row 27.

However I am getting the following error message Line 7: Table addRows: The argument is invalid or missing or has an incorrect format.

This appears to becoing from numRow, where am I going wrong with this code?

1.function main(workbook: ExcelScript.Workbook) {
2.let selectedSheet = workbook.getActiveWorksheet();
3. let table = workbook.getTable("Table1");
4. let startRow = 27;
5. let numRow = 50;
6.
7.table.addRows(startRow,numRow);
8.}

Thanks
The second argument of the method addRows requires a 2-dimensional array ([][]).
For example, I want to insert two blank rows at row 1 (because Office Scripts does not support "any" type, I have to write const row = ["",""] instead of const row = new Array(2)):

1681908819208.png
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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