+ Reply to Thread
Results 1 to 3 of 3

Office Script to Check if Table Header Exists

  1. #1
    Forum Contributor
    Join Date
    07-01-2018
    Location
    Adelaide, South Australia
    MS-Off Ver
    Office 365, & Excel 2016 on windows 10, & 14.7 for mac, & Excel 2015 for mac
    Posts
    173

    Office Script to Check if Table Header Exists

    I'm working on a macro in OfficeScript.
    Among other things I need it to check if a column header exists in the given table and add a column if it doesn't exist. This part doesn't seem to work.

    Here is the relevant snippet
    Please Login or Register  to view this content.
    The office script documentation says that if getColumn should return 'undefined' if a column is not found, so I also tried number of tests for an undefined variable, but all return false.

    https://learn.microsoft.com/en-us/ja...lumn-member(1)

    So at this point I am thinking I may need to add a function to loop through all the headers, but that feels like overkill.
    Any suggestions?

    Here is my full code. I attached a sample workbook with appropriately named worksheet and table.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by truk2; 08-17-2023 at 07:51 PM.
    If my solution helped, please consider adding Rep

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Office Script to Check if Table Header Exists

    Cross-posted here now: https://stackoverflow.com/questions/...missing-header

    Your function code works for me if the table doesn't have that column. (It doesn't work with your sample file and the full code you posted because a previous missing column causes the code to abort before that)
    Rory

  3. #3
    Registered User
    Join Date
    12-30-2021
    Location
    Toronto
    MS-Off Ver
    365
    Posts
    51

    Re: Office Script to Check if Table Header Exists

    The following code will check if column "Score" exists and add it to the table if it doesn't exsit.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Office Script to Get Display Format (check if conditional formatting active)
    By BitcoinBadger in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-16-2022, 02:58 PM
  2. [SOLVED] SOLVED Help with Office Script to convert a Table to UPPER case
    By xxxrob in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-01-2022, 05:50 PM
  3. Replies: 3
    Last Post: 08-14-2021, 05:25 PM
  4. Check if a Table Exists
    By mowens74 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-03-2020, 09:08 AM
  5. [SOLVED] Check if a value exists in a table
    By Kappany in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-08-2015, 02:42 AM
  6. Check if Column Header Exists?
    By uberathlete in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-23-2014, 12:32 PM
  7. [SOLVED] Match a value in a table and print the header of that column if value exists
    By norms in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-25-2013, 06:48 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1