<< All versions

Skill v1.0.0

currentAutomated scan100/100
hydr0pon1c/skills-on-the-fly/209-30
──Details
PublishedNovember 26, 2026 at 01:29 AM
Content Hashsha256:0fc51da528517212...
Git SHAfc2c0936b42a
──Files
Files (1 file, 7.1 KB)
SKILL.md7.1 KBactive
SKILL.md · 65 lines · 7.1 KB

metadata: version: "1.0.0"


SKILL.md

When to use

Use this skill when the user provides a VBA code snippet that contains a logical or syntax error, and the task is to correctly implement the intended operation on a spreadsheet using Python. The user’s code often mistakenly assigns a Boolean comparison result to a cell instead of performing the desired transformation. Typical symptoms: all cells in a column become TRUE or FALSE after running the VBA code.

Target contract:

  • The instruction describes a VBA bug involving per-cell string manipulation (e.g., removing the last N characters, replacing substrings, or conditionally deleting rows).
  • The spreadsheet path, sheet name, target column, and the cell range (answer_position) are provided. The answer must be a modified .xlsx file at the specified output path.
  • The task is Sheet-Level Manipulation (the answer covers an entire range, but the operation may only affect data cells, not headers).
  • Performance matters: the number of rows can be very large (up to 500 000). Row‑by‑row operations (especially deletion) will time out; use bulk read/write instead.

Before acting, gather:

  • Exact sheet name and column letter/position (from spreadsheet_content and answer_position).
  • Whether row 1 is a header that must be left unchanged.
  • The actual data type of each cell in the target column (string with possible None).
  • The exact transformation: remove last X characters, keep only characters matching a pattern, replace a character, etc.

Possible Failure Modes

  1. Copying the VBA comparison error into Python – writing cell.value = ("C2") == Left(...) or any Python equivalent that returns a Boolean instead of the transformed string.
  2. Modifying the header row – applying the transformation to row 1 when the VBA started at row 2 and the instruction implies data starts after a header.
  3. Performance timeout – iterating over each cell and modifying it individually (works for small datasets, but on 500 000 rows the 60‑second limit will be reached). Use a bulk read/transform/write pattern.
  4. Forgetting to skip empty/NaN cells – calling .value[:-3] on a None value raises an error. Check that the cell is a string before slicing.
  5. Off‑by‑one errors in range – processing beyond the answer_position boundary or missing the last row specified by the range. Use the exact range from the context (e.g., 'Data to Import'!C1:C6066), but apply the transformation only to data rows inside that range.
  6. Using `str()` on non‑string cells – converting a number to string may produce unwanted quotes or formatting. Only modify cells that are already strings.
  7. Ignoring single‑cell vs. range‑wise logic – the VBA used ws.Range("C2").End(xlUp) to find the last used row, but the answer position may be larger; the solution must respect the given range, not guess.

Possible Procedures

  1. Load the workbook and target sheet using openpyxl.load_workbook(path).
  2. Determine the effective row range:
  • Use the answer_position to get the sheet range (e.g., 'Data to Import'!C1:C6066). Parse the start and end rows.
  • If the VBA loop started at row 2 (or the instruction implies data starts at row 2), treat row 1 as a header and skip it during transformation.
  • If needed, also read the entire sheet’s used range to handle missing rows gracefully.
  1. Collect all target column values into a list (only rows in the data range, skip header). For each cell value:
  • If the value is None (empty cell), decide whether to leave it as is or delete the row (based on the instruction). For a “remove last characters” task, leave it unchanged.
  • If the value is not a string (e.g., number, date), skip transformation or convert? Usually the instruction applies to text (postcodes), so skip non‑strings.
  • If it is a string, apply the transformation (e.g., value[:-3] to remove last 3 characters). Handle empty or too‑short strings gracefully (e.g., leave as is or set to empty string?).
  1. Write the transformed values back to the same cell positions. For large row counts, avoid one‑by‑one cell writes in a loop if it becomes slow. Instead, after collecting the transformed list, write the entire column at once using a for col_idx, value in enumerate(transformed_values, start=start_row) loop – openpyxl handles this quickly.
  • Alternative: read all rows and columns into a 2D list (including header), apply transformation to the target column indices, then clear the sheet and write the entire matrix. This is safer for very large ranges.
  1. Save the workbook to the specified output_path.
  2. Optimisation check: If the number of rows >10 000, prefer the bulk‑read/write‑matrix approach over row‑by‑row deletion or cell‑by‑cell assignment.

Decision Points

  • Does the transformation apply to header row? Check answer_position start cell. If it’s C1, you must verify whether the instruction implies a header. The user’s VBA started at C2 – typical. If in doubt, inspect spreadsheet_content for a header label in row 1 (e.g., “Location”). Preserve that row.
  • What to do with non‑string cells? If the column is expected to be all postcode strings, skip any numeric or blank cells (or convert all to string first, but that may break validation). Better to skip and leave untouched.
  • How to handle cells where the string is shorter than the number of characters to remove? Decide: leave unchanged, set to empty string, or pad with empty? For a postcode where length is always ≥3, this is safe; still guard with an if len(value) >= n.

Verification Checklist

  • [ ] Output file exists at the exact output_path and is a valid .xlsx file.
  • [ ] Answer position is honoured: only cells within answer_position (e.g., 'Data to Import'!C1:C6066) have been modified; cells outside this range are unchanged.
  • [ ] Header row (row 1) is preserved if the VBA loop started at row 2 – check that the header cell still contains its original text or is unchanged.
  • [ ] No FALSE/TRUE values appear in the final spreadsheet; all transformed cells contain the expected string (last N characters removed).
  • [ ] Empty/NaN cells are not accidentally filled with an empty string or error – they remain empty (None) if they were originally empty.
  • [ ] Large‑row performance: the solution completes within the execution timeout (60 s). If the row count is high (>50 000), confirm that the code used a bulk read/write or matrix approach, not a per‑cell loop with deletion.
  • [ ] Transformation correctness: For a sample of rows (first, last, and a middle row), manually verify that the correct number of characters have been removed from the end of the string.
  • [ ] No side effects on other sheets – only the target sheet is modified.
  • [ ] Recovery check: If any ambiguous evidence (e.g., answer_position includes a row that is clearly a header, or the transformation description is unclear), the agent should either re‑read the instruction or apply a safe default (skip header) and note the assumption.
All versions