Tag: Google Apps Script tutorial

  • How to Delete All Rows with Specific Text in Google Sheets (Manual + Script)

    🗑️ How to Delete All Rows Containing Specific Text in a Column in Google Sheets

    When working with large datasets, you may need to delete all rows where a certain word or value appears in a specific column — like removing all rows where column B says "Cancelled".

    You can do this manually, with filters, or use Google Apps Script to automate it.


    ✅ Method 1: Use Filter to Delete Rows Containing Specific Text (Manual)

    Steps:

    1. Select your data range.
    2. Go to Data > Create a filter.
    3. Click the filter icon in the target column (e.g., Column B).
    4. Uncheck all and select only the value you want to delete (e.g., "Cancelled").
    5. Select the filtered rows by clicking the row numbers.
    6. Right-click > Delete selected rows.
    7. Turn off the filter.

    ✅ Best for: Small to medium datasets.


    ✅ Method 2: Use Google Apps Script (Automatic & Reusable)

    If you want a repeatable way to delete rows based on a value, use this simple script.

    🔧 Script to Delete Rows Containing Specific Text:

    1. Click Extensions > Apps Script.
    2. Paste this code:
    javascriptCopyEditfunction deleteRowsWithText() {
      const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
      const columnToCheck = 2; // Column B (use 1 for A, 2 for B, etc.)
      const textToDelete = "Cancelled";
      const data = sheet.getDataRange().getValues();
      
      for (let i = data.length - 1; i >= 0; i--) {
        if (data[i][columnToCheck - 1] === textToDelete) {
          sheet.deleteRow(i + 1);
        }
      }
    }
    
    1. Save and click ▶️ Run.

    ✅ Customizable: Change columnToCheck and textToDelete as needed.

    ✅ Why loop backward? It prevents row shifting issues while deleting.


    🚀 Want to Learn All These Google Sheets Hacks (and More)?

    If you’re enjoying these powerful techniques, you’ll love our full Google Sheets training!

    🔗 💡 Unlock the Power of Google Sheets – Enroll Now

    🎯 Limited-Time Offer: ₹1,299 → ₹449 only!

    📘 Course Highlights:

    • 🎥 29 video lessons
    • 🕒 3 hours 46 minutes total duration
    • 🔍 Beginner to advanced: formulas, pivot tables, scripts, data analysis
    • 🧑‍🏫 Learn through real-world examples and practical demos

    Whether you’re managing business reports, automating tasks, or cleaning data — this course helps you master Google Sheets efficiently.


  • How to Get a List of Sheet Names in Google Sheets (Step-by-Step)

    Google Sheets doesn’t offer a built-in formula to list sheet names directly like Excel VBA might. However, you can achieve it easily using Google Apps Script. Here’s how:

    ✅ Step 1: Open Google Apps Script

    1. Open your Google Sheets file.
    2. Click on Extensions > Apps Script.

    ✅ Step 2: Paste This Script

    In the script editor, paste the following code:

    javascriptCopyEditfunction listSheetNames() {
      const ss = SpreadsheetApp.getActiveSpreadsheet();
      const sheets = ss.getSheets();
      const sheetNames = sheets.map(sheet => [sheet.getName()]);
      
      const outputSheetName = "Sheet List";
      let outputSheet = ss.getSheetByName(outputSheetName);
      
      if (!outputSheet) {
        outputSheet = ss.insertSheet(outputSheetName);
      } else {
        outputSheet.clear();  // Clear old data
      }
      
      outputSheet.getRange(1, 1, sheetNames.length, 1).setValues(sheetNames);
    }
    

    ✅ Step 3: Save and Run

    1. Click the 💾 Save icon and name your project.
    2. Click the ▶️ Run button.
    3. If prompted, authorize the script to access your spreadsheet.

    ✅ What Happens Next?

    • A new sheet called “Sheet List” will be created (or updated).
    • It will display the names of all sheets in your file—automatically.

    🚀 Want to Master Google Sheets from A to Z?

    🎯 Whether you’re just starting out or looking to boost your spreadsheet superpowers, our premium Google Sheets course is your gateway to mastery.

    🔗 Enroll Now – Unlock the Power of Google Sheets

    🔥 Offer: ₹1,299 ₹449 (Limited-Time Deal)

    What You’ll Get:

    • 📹 29 videos totaling 3 hours 46 minutes
    • ✅ From beginner basics to advanced data analysis
    • 📈 Learn formulas, pivot tables, data validation, automation & more
    • 💼 Ideal for students, professionals, entrepreneurs

    💡 With real-world examples and practical exercises, you’ll quickly become confident in handling data, automating tasks, and making smarter decisions.