Google Sheets Macros & Scripts Supercharged by Chat GPT
About
No channel description available.
Video Description
Google Sheets Macros & Scripts Supercharged by Chat GPT. #googlesheets **Overall Topic:** Enhancing a basic recorded Google Sheets macro using ChatGPT to make it more dynamic and powerful. **Part 1: Recording a Basic Macro (Manual Steps)** 1. **Start Recording:** Go to `Extensions - Macros - Record macro`. 2. **Add Column:** Create a new column named "Area Code". 3. **Format Header:** Make the new column's header bold. 4. **Add Formula:** Enter a `=LEFT(C2, 3)` formula in the first data row (D2) of the new column to extract the area code from the phone number column (C). 5. **Autofill Formula:** Use the suggested autofill (or manually drag down) to copy the formula down the column *for the specific range recorded*. 6. **Resize Columns:** Select relevant columns (A-D) and auto-resize them. 7. **Format Header Row:** Apply background color (purple) and font color (white) to the entire header row (A1:D1). 8. **Apply Borders:** Select the entire data range *recorded* (e.g., A1:D217) and apply all borders. 9. **Final Action:** Click cell A1. 10. **Save Macro:** Save the recorded steps, naming it "Macro1". **Part 2: Identifying Limitations of the Basic Macro** 1. **Run on Different Sheet:** Execute the saved "Macro1" on a different sheet ("July") that has *fewer* rows than the original sheet ("March"). 2. **Observe Problem:** Notice that while formatting applies, the formula and borders extend down to the original recorded row count (e.g., row 217), not the actual last row of the current sheet. This demonstrates the macro isn't dynamic. **Part 3: Using ChatGPT to Make the Macro Dynamic (Handling Variable Rows)** 1. **Access Script:** Go to `Extensions - Apps Script` to open the editor. 2. **Copy Code:** Locate and copy the Apps Script code generated for "Macro1". 3. **ChatGPT Prompt 1:** Paste the code into ChatGPT and ask it to modify the script to work dynamically, regardless of the number of rows (using the sheet's actual `getLastRow`). 4. **Apply ChatGPT Code 1:** Replace the original script with ChatGPT's first suggested update. 5. **Test & Identify Issue:** Run the updated macro. Observe that borders/formatting might be dynamic now, but the formula autofill might not work correctly (e.g., only fills the first cell or uses the old `autofill` range logic). 6. **ChatGPT Prompt 2 (Refinement):** Go back to ChatGPT, explain the formula fill issue, and ask for a fix. 7. **Apply ChatGPT Code 2:** Replace the script again with ChatGPT's refined code (which likely uses `setFormula` or `setFormulaR1C1` over the dynamic range instead of `autofill`). 8. **Verify Dynamic Rows:** Test the macro on sheets with different row counts ("May", "July", etc.) to confirm it now correctly formats and applies formulas only to the existing data rows. **Part 4: Using ChatGPT to Apply Macro to All Sheets** 1. **Copy Working Code:** Copy the currently working *dynamic* macro code from Apps Script. 2. **ChatGPT Prompt 3:** Paste the dynamic code into ChatGPT and ask it to modify the macro to run on *every sheet* within the Google Sheet file. 3. **Apply ChatGPT Code 3:** Replace the script with ChatGPT's new version, which now includes a loop (`forEach`) iterating through `spreadsheet.getSheets()`. 4. **Verify Multi-Sheet Execution:** Run the final "Macro1". Check several different sheets in the file to confirm the dynamic formatting and formulas have been applied across all of them.
Elevate Your Google Sheets Game
AI-recommended products based on this video

(2 Pack) Outlet Wall Mount Holder for Google Home Mini and Google Nest Mini, A Space-Saving Accessories with Cord Management for Google Mini Smart Speaker, No Messy Wires or Screws

INIU 45W Power Bank, Ultra Small 10000mAh Portable Charger, USB C in&Out Fast Charging Battery Pack, Travel External Phone Powerbank Compatible with iPhone 16 15 Samsung S25 S24 Google Pixel iPad etc

INIU Power Bank, USB C in&Out Slimmest 10000mAh Portable Charger, Triple 3A High-Speed Charge External Battery Pack, Flashlight Phone Charger for iPhone 16 15 14 13 12 Samsung S22 S21 Google LG iPad

(2 Pack) Outlet Wall Mount Holder for Google Home Mini and Google Nest Mini, A Space-Saving Accessories with Cord Management for Google Mini Smart Speaker, No Messy Wires or Screws

Magnetic Car Mount Air Vent Cell Phone Holder, Universal Vehicle Dash Dashboard Ac Airvent Cellphone Magic Stand with Clip Hook, for iPhone 16 15 Samsung Lenovo Google etc

100W USB C Universal Laptop Charger Fit for Lenovo MacBook HP Dell Acer Asus Thinkpad Google MSI LG Samsung Huawei, ROG Ally, Steam Deck, Chromebook Computer and All USB-C Devices

INIU Power Bank, USB C in&Out Slimmest 10000mAh Portable Charger, Triple 3A High-Speed Charge External Battery Pack, Flashlight Phone Charger for iPhone 16 15 14 13 12 Samsung S22 S21 Google LG iPad



















