Google Sheets Macros & Scripts Supercharged by Chat GPT
Learn Google Sheets & Excel Spreadsheets
·
Beginner
·📊 Data Analytics & Business Intelligence
·1y ago
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. **Appl
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
More on: Data Literacy
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
SQL to Python: The Exact Transition Every BA Needs to Make
Medium · Data Science
SQL to Python: The Exact Transition Every BA Needs to Make
Medium · Python
Psychology of Decision Support Systems (DSS)
Medium · Data Science
Snowflake Cortex AI: Your Smartest Hire That Never Sleeps
Medium · Data Science
🎓
Tutor Explanation
DeepCamp AI