79625067

Date: 2025-05-16 11:29:21
Score: 5.5
Natty:
Report link

Thanks to the link provided by @Dmitry Kostyuk, I tried to improve my script with the help of GPT. However, I'm not a professional coder, and the best practices suggested in the guide below: Google Apps Script Best Practices seem a bit beyond my current skill level.

Unfortunately, the code still isn't working as expected !

function V2() {
  // Définis les colonnes à remplir
  const columns = [
    "I", "K","L","M","N","O","P","Q", "S","T","U","V","W","X","Y",
    "AA","AB","AC","AD","AE","AF","AG", "AI","AJ","AK","AL","AM","AN","AO",
    "AQ", "AS","AT","AU","AV","AW","AX",
    "AZ","BA","BB", "BD","BE","BF","BG","BH","BI","BJ", 
    "BL","BM","BN","BO","BP","BQ","BR", 
    "BT","BU","BV","BW","BX","BY","BZ", 
    "CB","CC", "CE","CF", "CH","CI", 
    "CK","CL","CM","CN","CO", "CQ", 
    "CS","CT","CU","CV","CW","CX","CY",
    "DA", "DC", "DE", "DG","DH"
  ];

  // Ouvre le classeur actif
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("0_MASTER BDD");
  
  // Détecte la dernière ligne non vide de la colonne B
  const lastRow = sheet.getRange("B:B").getLastRow();
  
  // Traite les colonnes en une seule opération
  const batchUpdates = columns.map(col => {
    const colIndex = sheet.getRange(`${col}1`).getColumn();
    
    // Récupère la formule en R1C1
    const formulaR1C1 = sheet.getRange(11, colIndex).getFormulaR1C1();
    
    // Détermine la plage cible (ligne 12 à la dernière ligne)
    const targetRange = sheet.getRange(12, colIndex, lastRow - 11);
    
    // Remplit la plage
    return { range: targetRange, formula: formulaR1C1 };
  });
  
  // Applique toutes les formules d'un coup
  batchUpdates.forEach(({ range, formula }) => {
    range.setFormulaR1C1(formula);
  });
  
  Logger.log(`Formules copiées dans ${batchUpdates.length} colonnes, jusqu'à la ligne ${lastRow}`);
}

the result log in the console :

12:40:49

Avis

Exécution démarrée

12:48:51

Erreur

Exception: Service Spreadsheets timed out while accessing document with id 1VilR1f8_Ir6v8aWk7U9sLC4lN5C4qpE0nzVQ91OeM0U.

It doesn't even fill a single column.

Am I missing something obvious? The logic seems correct to me, but it just doesn't produce the expected result.

Thanks in advance for any advice!

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • RegEx Blacklisted phrase (3): Thanks in advance
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • User mentioned (1): @Dmitry
  • Self-answer (0.5):
  • Looks like a comment (1):
  • Low reputation (0.5):
Posted by: antho2B