Excel Script for hiding Columns containing a defined cell

K, Y 21 Reputation points
2022-11-29T14:05:37.957+00:00

Hello,

im looking for help with my excel-script I'd like to use in my sharepoint file. I want the script to search the current workbook for all the cells containing the words "Funktion_ausblenden". Then, I'd like to hide the entire column, if it contains the cell with these words in it.

Unfortunately im new to the subject and don't know how to finish this script. I think I got the part where it searches for the cells containing the words. But I don't know how to hide the columns. Help would be much appreciated.

My current script:

function main(workbook: ExcelScript.Workbook) {
// Get the current, active worksheet.
let worksheet = workbook.getActiveWorksheet();
let noCells = worksheet.findAll("Funktion_ausblenden", { completeMatch: true });
//Spalten ausblenden
noCells.getEntireColumn().setColumnHidden (true)
}

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,456 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yutao Huang - MSFT 701 Reputation points Microsoft Employee
    2022-11-30T19:17:40.74+00:00

    Hello @K, Y ,

    You can try something like this:

       function main(workbook: ExcelScript.Workbook) {  
         // Get the current, active worksheet.  
         let worksheet = workbook.getActiveWorksheet();  
         let noCells = worksheet.findAll("Funktion_ausblenden", { completeMatch: true });  
         if (noCells) {  
           //Spalten ausblenden  
           noCells.getAreas().forEach(range => range.setColumnHidden(true));  
         }  
       }  
    

    worksheet.findAll() returns a RangeAreas object. Calling getAreas() on this object can return an array of Range objects, where you can iterate through and hide their columns accordingly.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful