Office Script - How to i ) delete a column and ii) find the subtotal of a column based on the column headers ?

kchuphone

New Member
Joined
Jun 6, 2022
Messages
7
Office Version
  1. 2021
Platform
  1. Windows
I am trying to use Office Script to i) delete a column with a header named "Object Type" and
ii) sum up the cells (all the visible filtered cells) in the column named "Hits".

I'm new to Office Script and am stuck. I get the following error for getColumnByName: Cannot read properties of undefined (reading 'getColumnByName')

Any help will be super appreciated!


VBA Code:
function main(workbook: ExcelScript.Workbook) {
 
  let selectedSheet = workbook.getActiveWorksheet();

  let table = workbook.getTables()[0];

//delete a column with a header named "Object Type"
 let rangeObj = table.getColumnByName("Object_Type").getRange();
  selectedSheet.getRange(rangeObj).delete(ExcelScript.DeleteShiftDirection.left);

//Sum up the cells  (all the visible filtered cells) in the column named "Hits"
  let rangeHits = table.getColumnByName("Hits").getRange();
  selectedSheet.getRange(rangeHits).???


}


SampleObject TypeHits
1A24
2B3444
3C334
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Isn't the header "Object Type" not "Object_Type"?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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