V
V
Villert2022-03-09 20:28:24
Google Apps Script
Villert, 2022-03-09 20:28:24

How to check google script if there is a sheet with the same name in the table as the active one?

How to check with google script code if there is a sheet with the same name in the table as the active one?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Ivanov, 2022-03-10
@Villert

Most likely, you want to check if there is a sheet with the given name in the workbook. Just take this sheet - it will immediately become clear - it is or it is not.
Example

const sheetName = 'Sheet1';
const sheet = book.getSheetByName(sheetName);
if(sheet){
  cnsole.log(`Лист с именем ${sheetName} есть`);
}

Or, more commonly used, creating a sheet if it doesn't exist
const sheetName = 'Sheet1';
const sheet = book.getSheetByName(sheetName) || book.insertSheet(sheetName);

G
Grigory Boev, 2022-03-09
@ProgrammerForever

There cannot be two sheets with the same name.

V
Villert, 2022-03-10
@Villert

I expressed myself incorrectly, sorry - check that there is no sheet in the book with the same name as the one being created.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question