AI for Automation
πŸ“Š Excel Automation

Step 6 / 22

πŸ“Š Excel Automation

Data aggregation + summaries + auto-generated charts

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.

Type in 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.

Terminal output (example)
πŸ“Š 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
Generated result.xlsx β€” summary table with SUM formulas
result.xlsx generated by Claude Code β€” department summary table with SUM formulas

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.

1

Installs Python libraries & reads the file

Automatically installs openpyxl and pandas, then reads the Excel file. Analyzes all sheets even if there are multiple.

2

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.

3

Creates pivot aggregation by department/month

Groups data by department and month, calculating totals, averages, etc. Same result as creating a pivot table yourself.

4

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.

5

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.

Type in Claude Code
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:

βœ“Auto-generates a sample Excel file (sales_data.xlsx) with departmental sales
βœ“Classifies and aggregates data by department and month
βœ“Creates a summary sheet with actual Excel formulas (SUM, AVERAGE, etc.)
βœ“Saves as result.xlsx (original preserved)

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.

1

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 thisDo this instead
"Clean up data.xlsx""Clean up data.xlsx and save as a new file. Preserve original."
2

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.

ResultPrompt difference
Cell shows 1,500,000 (static value)"Calculate the total"
Cell shows =SUM(B2:B10) (formula)"Add the total as a SUM formula"
3

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"

4

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.

Example prompt
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.