Site icon Kaizen.Personal computer work.

Delete cells, rows, and columns.(Microsoft Excel Office Scripts)

Japanese version.

Operations

Using script recordings will target the active sheet.

However, that would change the behavior depending on where the script is run, so it is recommended to specify the sheet name as well.

Change the red text accordingly.

Cell range.delete(Shift direction after deletion);

Shift direction after deletion

Specify either the bottom The difference is the last one, up or left.

Cell deletion

Specify by cell address

To delete cell A1 on the Test sheet, do the following

Specify the cell address with the getRange method.

// Delete cell A1 and move it up. workbook.getWorksheet("Test").getRange("A1").delete(ExcelScript.DeleteShiftDirection.up); 

// Delete cell A1 and move it to the left. workbook.getWorksheet("Test").getRange("A1").delete(ExcelScript.DeleteShiftDirection.left);

Specified by index (sequential number starting from 0)

To delete cell A1 on the Test sheet, do the following

Specify the index in the getCell method, where the first column (column A) and the first row are both 0.

Cell A1 becomes getCell(0,0).

// Delete cell A1 and move it up.
workbook.getWorksheet("Test").getCell(0,0).delete(ExcelScript.DeleteShiftDirection.up);

// Delete cell A1 and move it to the left. 
workbook.getWorksheet("Test").getCell(0,0).delete(ExcelScript.DeleteShiftDirection.left);

Row deletion

To delete the first row of the Test sheet, do the following.

workbook.getWorksheet("Test").getRange("1:1").delete(ExcelScript.DeleteShiftDirection.up);

Column deletion

To delete the first column (column A) of the Test sheet, do the following.

workbook.getWorksheet("Test").getRange("A:A").delete(ExcelScript.DeleteShiftDirection.left);

For those who want to learn Office script effectively

The information on this site is now available in an easy-to-read e-book format.

Or Kindle Unlimited (unlimited reading).

You willl discover how to about basic operations.

By the end of this book, you will be equipped with the knowledge you need to use Excel Office Script to streamline your workflow.

Links

Office Scripts Articles

Exit mobile version