Library › Coding AI › Office and admin

Copy approved requests to another tab with Apps Script

Practice: Setting limits and rules. About 5 minutes.

About this exercise

Write a Google Apps Script function named copyApproved that copies every row from the Requests tab whose Status (column D) is Approved onto the bottom of the Approved tab. Copy only columns A to D, because the Approved tab has no Notes column, and skip the header row. Keep it to a function you run by hand: no menus, triggers, logging or try/catch. One code block, at most 15 lines, then under 25 words outside the code.

Common mistakes when you ask AI for this

  • Not describing both tabs. The AI copies whole rows, Notes included, into a tab that has only four columns. Try: Add: "Copy only columns A to D; the Approved tab has no Notes column."
  • Leaving out the names. The AI picks its own function name and uses the active sheet. Try: Add: "Function copyApproved, get both tabs with getSheetByName, skip row 1."
  • Not ruling out extras. The AI adds a custom menu, logging and error handling you didn't ask for. Try: Add: "No menus, triggers, logging or try/catch."
  • Getting a menu of options. The AI likes to offer two or three versions of the script, so you're left to pick and test them yourself. Try: Add: "Give one script only, in one code block, no alternatives."
  • Getting a tutorial. By default the AI explains every part of the code at length, which you then have to scroll past. Try: Add: "After the code, one line under 15 words. Nothing else."

What a strong prompt includes

  • Names the function and tabs
  • Limits the columns
  • Rules out extras
  • Asks for one answer only
  • Caps the code length

Practice this now ↑

Related exercises