Get Table Name With Apps Script

I have two tables, namely Table A and Table B. Each table I want to identify the name of the table in column C
matches the table names that have been defined in column A.

The script I’ve made is like this:

tableName () function {
  let ss = SpreadsheetApp.getActiveSpreadsheet ();
  let cColumn1 = ss.getRange ('C3: C7');
  let cColumn2 = ss.getRange ('C11: C15');

  let tableName1 = ss.getRange ('C2'). getValue ();
  let tableName2 = ss.getRange ('C9'). getValue ();

  cColumn1.setValues   (tableName1);
  cColumn2.setValues   (tableName2);

But my script is still manual, we have to specify the start line and end line of the table.
To identify the name of the table I’ve ever made with a formula, so with this formula, we don’t need to specify the position
the name of the reference table.

= ARRAYFORMULA (IF ((B: B = "") + (B: B = "Name") ,, VLOOKUP (ROW (A: A), IF (LEN (REGEXEXTRACT (A: A, "TD+") ), {ROW (A: A), REGEXEXTRACT (A: A, "TD+")}, 0), 2)))

This formula is very heavy if the amount of data is large.

My Spreadsheet.

Go to Source
Author: Lutfi Creativesys