Library › Coding AI › Office and admin
Write a tight VBA macro that hides finished tasks
Practice: Setting limits and rules. About 5 minutes.
About this exercise
You want a VBA macro named HideDoneRows that hides every row on the sheet named Tasks whose Status in column F is done, starting at row 2 and stopping at the last row with data in column A (the list grows weekly). Status is typed inconsistently, so done must match any capitalization and stray spaces. No message boxes and no On Error lines. One code block of at most 12 lines, then under 25 words outside the code.
Common mistakes when you ask AI for this
- Not naming the sheet. The AI uses ActiveSheet, so running it from another tab hides the wrong rows. Try: Add: "Work on the sheet named Tasks, not the active sheet."
- Leaving the range open. The AI loops to a fixed row like 1000 or starts at row 1 and hides the header. Try: Add: "Start at row 2, stop at the last row with data in column A."
- Not mentioning messy statuses. The AI checks for exactly "Done" and misses "done" and "DONE ". Try: Add: "Match done in any capitalization, ignoring spaces. No MsgBox or On Error."
- Getting a menu of options. The AI likes to offer two or three versions of the macro, so you're left to pick and test them yourself. Try: Add: "Give one macro 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 macro and the sheet
- Sets the row range
- Covers messy capitalization
- Rules out extras
- Caps the code length
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)