A
A
Alina Shah2021-07-16 14:44:58
Google Sheets
Alina Shah, 2021-07-16 14:44:58

How do I make the first letter in a cell capitalized?


https ://docs.google.com/spreadsheets/d/1vqKnsN_8qQ... it is written that it can delete, change my files on the disk.

I write only one word in a cell - first name or last name or patronymic and I would like the first letter to be capitalized - is this possible?
without creating somewhere in the side of the range

I am familiar with the formula =PROPER(P2), but I would like it to change exactly in the cell in which I enter the name.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2021-07-19
@Shah_Alina

You need to add the following code to the Table Scripts project

/**
 *
 * @param {GoogleAppsScript.Events.SheetsOnEdit} e
 */
function onEdit(e) {
  const allowRanges = [
    { sheetName: 'Заглавная буква', cells: ['B2', 'B3', 'B4'] },
    { sheetName: 'Стартовая страница', cells: ['B2', 'C2', 'D2'] },
  ]; // Список
  const sheetNames = allowRanges.map(r => r.sheetName);

  if (e && e.range) {
    const sheet = e.range.getSheet();
    if (
      sheetNames.indexOf(sheet.getName()) > -1 &&
      allowRanges.find(r => r.sheetName === sheet.getName()).cells.indexOf(e.range.getA1Notation()) > -1
    ) {
      const value = '' + e.range.getValue();
      e.range.setValue(value.slice(0, 1).toLocaleUpperCase() + value.slice(1).toLocaleLowerCase());
    }
  }
}

For the program to react correctly, you need to set the line
const allowRanges = [
{ sheetName: 'Capital letter', cells: ['B2', 'B3', 'B4'] },
{ sheetName: 'Start page', cells: ['B2 ', 'C2', 'D2'] },
]; // List
for all cells where you are going to catch these changes
60f514d1c79fe510480422.gif
Example in Spreadsheet https://docs.google.com/spreadsheets/d/19bQjuZpRaE...
Doesn't work for a group of cells

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question