Excel VBA Macro Writer & Installer
ChatGPT
Code & Development
#Beginner#Advanced#Step by Step
Stop doing the same spreadsheet cleanup by hand. Paste it into ChatGPT with your task and get a beginner-proof macro package: guarded, version-aware code with a safe CONFIG section, plain-English install steps, and its honest limits. For Excel on Microsoft 365. Singles are listed in small numbers; when this one cycles out, it's kit-only.
I prepared this as a buyer-ready VBA package with beginner-friendly instructions and the safety checks included.
## 1. **What this macro does**
This macro removes completely empty rows from **Sheet1**, formats **Column G** as currency, and automatically adjusts column widths so the worksheet is easier to read. It is designed for Microsoft 365 Excel and includes safety checks so the user must approve before any rows are deleted.
## 2. **Safety notice**
Always test this macro on a COPY of your workbook first — never run a new macro on your only copy of important data.
## 3. **The complete macro**
```vb
Option Explicit
Sub CleanSheet1FormatCurrencyAndAutofit()
'========================
' CONFIG SECTION
' Change ONLY these settings to customize the macro.
' Do not edit the main logic below unless you know VBA.
'========================
Const TARGET_SHEET_NAME As String = "Sheet1"
Const HEADER_ROW As Long = 1
Const CURRENCY_COLUMN As String = "G"
Const CURRENCY_FORMAT As String = "$#,##0.00"
'========================
' VARIABLE DECLARATIONS
' These store the workbook, worksheet, and row information.
'========================
Dim ws As Worksheet
Dim lngLastRow As Long
Dim lngRow As Long
Dim intAnswer As VbMsgBoxResult
Dim strMessage As String
On Error GoTo ErrorHandler
'========================
' FIND THE TARGET WORKSHEET
' This attempts to locate the sheet named in the CONFIG section.
' If the name is wrong, the error handler explains the issue.
'========================
Set ws = ThisWorkbook.Worksheets(TARGET_SHEET_NAME)
'========================
' FIND THE LAST USED ROW
' This determines where the cleanup process should stop.
'========================
lngLastRow = ws.Cells.Find(What:="*", _
After:=ws.Cells(1, 1), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
'========================
' ASK FOR PERMISSION BEFORE DELETING ROWS
' Deleting rows changes the workbook, so the user must approve.
' The default option is No for safety.
'========================
strMessage = "This macro will permanently delete completely empty rows below the header row on " & _
TARGET_SHEET_NAME & "." & vbCrLf & vbCrLf & _
"Do you want to continue?"
intAnswer = MsgBox(strMessage, vbYesNo + vbDefaultButton2, "Confirm Row Deletion")
If intAnswer = vbNo Then
MsgBox "No changes were made. The macro has safely stopped.", vbInformation, "Cancelled"
Exit Sub
End If
'========================
' DELETE EMPTY ROWS
' Rows are checked from the bottom upward because deleting rows
' from the top down can cause skipped rows.
'========================
For lngRow = lngLastRow To HEADER_ROW + 1 Step -1
If Application.CountA(ws.Rows(lngRow)) = 0 Then
ws.Rows(lngRow).Delete
End If
Next lngRow
'========================
' FORMAT THE CURRENCY COLUMN
' This changes only the display format of Column G.
' It does not change the stored values.
'========================
ws.Columns(CURRENCY_COLUMN).NumberFormat = CURRENCY_FORMAT
'========================
' AUTOFIT ALL COLUMNS
' This adjusts widths automatically for readability.
'========================
ws.Columns.AutoFit
'========================
' COMPLETION MESSAGE
' Lets the user know the macro finished successfully.
'========================
MsgBox "The cleanup and formatting process is complete.", _
vbInformation, _
"Finished"
Exit Sub
ErrorHandler:
'========================
' FRIENDLY ERROR MESSAGE
' Prevents confusing technical errors from appearing.
' Explains what the beginner should check instead.
'========================
MsgBox "The macro could not complete the task." & vbCrLf & vbCrLf & _
"Please check that:" & vbCrLf & _
"• The worksheet name in the CONFIG section is correct." & vbCrLf & _
"• The workbook and sheet are not protected." & vbCrLf & _
"• The data is not locked or restricted." & vbCrLf & vbCrLf & _
"No additional changes were made after the error occurred.", _
vbExclamation, _
"Macro Could Not Complete"
End Sub
```
## 4. **Install & run instructions**
1. **Make a copy of your workbook first.**
Save a duplicate copy of your Excel file before installing the macro. This protects your original data.
2. **Enable the Developer tab in Excel.**
- Open Excel.
- Click **File**.
- Click **Options**.
- Select **Customize Ribbon**.
- Check the box labeled **Developer**.
- Click **OK**.
3. **Open the VBA editor.**
- Open the workbook where you want the macro.
- Press **Alt + F11** on your keyboard.
- The VBA editor window will open.
4. **Insert a new module.**
- In the VBA editor, click **Insert** at the top menu.
- Select **Module**.
- A blank code window will appear.
5. **Paste the macro code.**
- Copy the complete macro above.
- Paste it into the blank module window.
6. **Return to Excel.**
- Press **Alt + Q**.
- This closes the VBA editor and returns you to Excel.
7. **Run the macro.**
- Press **Alt + F8**.
- Select:
`CleanSheet1FormatCurrencyAndAutofit`
- Click **Run**.
8. **Approve the safety confirmation.**
- A message will appear before deleting rows.
- Choose **Yes** only after confirming you are working on the correct file.
- Choosing **No** exits safely without deleting anything.
**Microsoft 365 note:**
This macro uses standard VBA methods supported by Microsoft 365 Excel, including `Worksheet.Columns.AutoFit`, `NumberFormat`, and worksheet row deletion methods. No additional add-ins are required.
## 5. **Customization notes**
- **Change the worksheet name**
- Find:
```vb
Const TARGET_SHEET_NAME As String = "Sheet1"
```
- Replace `"Sheet1"` with your worksheet name.
- **Keep a different number of header rows**
- Find:
```vb
Const HEADER_ROW As Long = 1
```
- Change `1` to the number of rows that should stay above the cleanup area.
- **Format a different column as currency**
- Find:
```vb
Const CURRENCY_COLUMN As String = "G"
```
- Replace `"G"` with another column letter.
- **Use a different currency format**
- Find:
```vb
Const CURRENCY_FORMAT As String = "$#,##0.00"
```
- Examples:
- Whole dollars:
```vb
"$#,##0"
```
- Euros:
```vb
"€#,##0.00"
```
## 6. **Assumptions & edge cases**
**Assumptions**
- The workbook contains a worksheet named `Sheet1` unless changed in the CONFIG section.
- Row 1 contains headers and should not be deleted.
- Empty rows are rows where every cell is blank.
- Column G contains values that can reasonably be displayed as currency.
**Merged cells**
- Merged cells may prevent normal row deletion or formatting.
- The macro will stop safely and display an error message if Excel cannot complete the operation.
**Active filters**
- Filtered data may affect what the user sees, but the macro works against the worksheet data itself.
- It is recommended to remove filters before running if the user wants a visual cleanup of only visible rows.
**Hidden rows**
- Hidden empty rows are still considered empty and may be deleted if they meet the deletion criteria.
**Missing or misspelled sheet name**
- The macro will stop and show a friendly message.
- Update `TARGET_SHEET_NAME` in the CONFIG section to match the actual worksheet name.
**Blank or malformed data**
- Blank cells in Column G remain blank.
- Text values in Column G are not converted; only the display format is applied.
**Protected workbook or worksheet**
- If the workbook or sheet is protected, Excel may block deleting rows or formatting.
- Remove protection, run the macro, then re-enable protection if needed.
**Destructive operations**
- The only destructive operation in this macro is deleting empty rows.
- No cells are cleared, overwritten, renamed, or new sheets added.
- The macro always asks for confirmation before deleting rows.
I can also help turn this into a more polished **commercial Etsy/Gumroad-ready VBA product package** with a README, cover page, screenshots checklist, and buyer troubleshooting guide.
---
If you want, I can:
- :chatgpt-content-reference{index="1"}
- :chatgpt-content-reference{index="2"}
- :chatgpt-content-reference{index="3"}1 / 4
