0
0
Excelspreadsheet~15 mins

VBA editor basics in Excel - Real Business Scenario

Choose your learning style9 modes available
Scenario Mode
👤 Your Role: You are an office assistant learning to automate tasks in Excel.
📋 Request: Your manager wants you to create a simple macro that formats a sales report with bold headers and autofit columns.
📊 Data: You have a sales report table with columns: Date, Product, Quantity, and Sales Amount.
🎯 Deliverable: Create a VBA macro that formats the header row in bold and adjusts the column widths to fit the content.
Progress0 / 4 steps
Sample Data
DateProductQuantitySales Amount
2024-01-01Apples1050
2024-01-02Bananas520
2024-01-03Cherries1575
2024-01-04Dates735
2024-01-05Elderberries330
1
Step 1: Open the VBA editor by pressing Alt + F11 in Excel.
No formula needed.
Expected Result
The VBA editor window opens.
2
Step 2: Insert a new module to write your macro.
In the VBA editor, click Insert > Module.
Expected Result
A new blank module appears in the editor.
3
Step 3: Write a macro named FormatReport that makes the first row bold and autofits columns A to D.
Sub FormatReport() Rows("1:1").Font.Bold = True Columns("A:D").AutoFit End Sub
Expected Result
Macro code is entered without errors.
4
Step 4: Return to Excel and run the macro.
Press Alt + F8, select FormatReport, then click Run.
Expected Result
The header row becomes bold and columns A to D adjust their width to fit the content.
Final Result
Date       | Product     | Quantity | Sales Amount
-----------------------------------------------
2024-01-01 | Apples      | 10       | 50
2024-01-02 | Bananas     | 5        | 20
2024-01-03 | Cherries    | 15       | 75
2024-01-04 | Dates       | 7        | 35
2024-01-05 | Elderberries| 3        | 30
The macro successfully formats the header row in bold.
Columns automatically adjust to fit the data width.
Using VBA editor basics, simple repetitive formatting can be automated.
Bonus Challenge

Modify the macro to also color the header row background light yellow.

Show Hint
Use Rows("1:1").Interior.Color = RGB(255, 255, 153) inside the macro.