Execute Now
If youβre repeating the same Excel tasks every week, one prompt is all you need. Copy the prompt below and paste it into Claude Code.
Read sales_data.xlsx,
aggregate sales by department,
add SUM formulas to the summary table,
and save as result.xlsx.
Don't touch the original.Prompt breakdown
This prompt contains all 3 formulas of a good prompt:
- Specify the file: "Read sales_data.xlsx"
- Describe the task: "aggregate sales by department, add SUM formulas"
- Specify the output: "save as result.xlsx"
It even adds "Donβt touch the original." A perfect prompt!
When you enter this prompt, Claude Code automatically writes and runs Python code. It reads the Excel file, analyzes it, aggregates it, and saves a new fileβall on its own.
Check the Results
After entering the prompt, youβll see output like this in the terminal.
π Starting Excel automation...
β
sales_data.xlsx read successfully
- Sheets: 1
- Rows: 1,247
- Columns: Date, Department, Product, Amount, Rep
π Cleaning data...
- 3 blank cells β filled with 0
- Date formats unified
π Department aggregation results:
ββββββββββββββββ¬βββββββββββββ¬βββββββββββ
β Department β Total Salesβ Count β
ββββββββββββββββΌβββββββββββββΌβββββββββββ€
β Sales Team 1 β $452,000 β 312 β
β Sales Team 2 β $387,000 β 287 β
β Marketing β $221,000 β 198 β
β Planning β $183,000 β 156 β
β Overseas β $315,000 β 294 β
ββββββββββββββββΌβββββββββββββΌβββββββββββ€
β Total β $1,558,000 β 1,247 β
ββββββββββββββββ΄βββββββββββββ΄βββββββββββ
β
SUM/AVERAGE formulas inserted into summary table
πΎ result.xlsx saved
π Original sales_data.xlsx β unchanged
Doing it manually
30 min β 2 hours
Copying, sorting, formulas, formatting...
With Claude Code
1 prompt, 30 seconds
AI handles the rest
Understanding: What Claude Does
Your Excel just got organized with a single prompt, right? Letβs look at what Claude Code actually did behind the scenes.
Installs Python libraries & reads the file
Automatically installs openpyxl and pandas, then reads the Excel file. Analyzes all sheets even if there are multiple.
Cleans data & handles missing values
Automatically fixes blank cells, incorrect formats, and duplicate data. This is usually the most time-consuming part when done manually.
Creates pivot aggregation by department/month
Groups data by department and month, calculating totals, averages, etc. Same result as creating a pivot table yourself.
Inserts Excel formulas (SUM / AVERAGE)
Instead of just placing static values, it inserts actual Excel formulas (=SUM, =AVERAGE) into cells. Data changes will auto-recalculate.
Saves to new file (preserving original)
Saves results as 'result.xlsx'. The original file is never modified.
What are openpyxl and pandas?
These are Python libraries that Claude Code uses to process Excel files.openpyxl directly reads and writes .xlsx files, andpandas analyzes and transforms data. You donβt need to know about these libraries β Claude Code installs and uses them automatically.
Try It Yourself
Donβt worry if you donβt have a practice Excel file. Claude Code will create sample data for you. Just enter the prompt below as-is.
No Excel file needed
Donβt worry if you donβt have a practice Excel file. Tell Claude Code "Create sample sales data" and it will auto-generate a practice file. If you have a real work file, you can use that too.
Create a sample sales data Excel file.
Then aggregate by department,
create a summary table with SUM formulas,
and save as result.xlsx.
Preserve the original.With this single prompt, Claude Code handles everything:
Verification Checklist
Have a real work file?
You can use your own actual Excel file instead of the sample. Put the file in your workspace folder and just change the filename in the prompt.
Example: "Read Feb_Sales.xlsx, aggregate by department, and create a summary table"
How to check the output file
Double-click result.xlsx in your workspace folder to open it in Excel (or Google Sheets). Click on a total cell in the summary sheet and youβll see it contains an actual formula like =SUM(B2:B6) instead of just a static number.
You can also use Claude inside Excel
Claude Pro subscribers and above can use Claude directly inside Excel. Similar to Microsoft 365 Copilot, but with Claudeβs powerful analysis capabilities right in your spreadsheet. Select cells and ask Claude for analysis without ever leaving Excel.
4 Excel Automation Tips
Here are useful tips for Excel work with Claude Code. These tips help you get more accurate and desired results.
Always specify to preserve the original
Always include "donβt touch the original" or"preserve the original" in your prompt. Claude Code preserves originals by default, but stating it explicitly makes it certain.
| Don't do this | Do this instead |
|---|---|
| "Clean up data.xlsx" | "Clean up data.xlsx and save as a new file. Preserve original." |
Explicitly say "use formulas"
By default, Claude Code puts calculated values (numbers) into cells. Saying "use formulas" makes it insert actual Excel formulas (=SUM, =AVERAGE, etc.). If the source data changes later, values auto-recalculate.
| Result | Prompt difference |
|---|---|
| Cell shows 1,500,000 (static value) | "Calculate the total" |
| Cell shows =SUM(B2:B10) (formula) | "Add the total as a SUM formula" |
Be specific about chart types
Saying just "make a chart" lets Claude pick something appropriate. But if you have a specific chart in mind, be explicit.
Bar chart
Good for comparisons
Line chart
Good for trends
Pie chart
Good for proportions
Combo chart
Mixed comparisons
Example: "Create a bar chart of sales by department"
Process multiple files at once
Have multiple Excel files? Use the "all xlsx files in the folder" pattern. Claude Code reads and processes all Excel files in the folder at once.
Read all xlsx files in the data folder,
merge them into one,
create a department summary table,
and save as consolidated-report.xlsx.You can do these too β application ideas
Excel automation isnβt limited to sales aggregation. These types of tasks can be automated the same way:
- Auto-generate weekly reports β Compile this weekβs data into a report template
- Meeting notes organization β Read meeting notes and organize into action items in Excel
- Sales analysis dashboard β Analyze sales data and generate an HTML report with charts
- Project status tracking β Consolidate progress from multiple sheets into a single status table
Common thread: one prompt does it all. The key is clearly stating "what," "how," and "where to save."
Claude Code subscription info
This exercise requires a Claude subscription. No API key neededβjust subscribe at claude.ai and youβre ready to go.
We recommend Claude Max ($100/mo). For repetitive Claude Code tasks like Excel automation, you need generous usage allowance. Starting with Pro ($20/mo) and upgrading if usage feels tight is also a good approach.
2 hours of weekly Excel work β 1 prompt, 30 seconds
No coding experience needed, no Excel expertise requiredβClaude Code handles it for you.