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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Isn't the header "Object Type" not "Object_Type"?
 
Upvote 0

Forum statistics

Threads
1,216,175
Messages
6,129,305
Members
449,499
Latest member
HockeyBoi

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