Ask ChatGPT for an Excel macro you can inspect and test

Name the workbook, sheet, exact range, and permitted changes when asking ChatGPT for a VBA macro. Request the code and a test plan before running it on a copy. A macro that works on the active sheet can affect the wrong report when you click another tab.

Use desktop Excel for VBA: Excel for the web can open workbooks containing macros, but cannot create, edit, or run those macros. Microsoft's VBA web limitation

Specify the smallest repeatable action

Suppose a fictional workbook has a sheet named Review. Cells D2:D6 contain review statuses. The job is to make the word Blocked bold and red, leaving its text and other cells untouched. When a previously blocked cell changes to another status, the next run should reset that cell's font to normal black.

That is a bounded formatting task. It does not need to delete rows, send email, download files, or run when the workbook opens. If ordinary conditional formatting meets your needs, you can use that instead; the example here teaches how to scope a manually run VBA procedure.

ChatGPT can help write and explain code. You still need to review the code and run it in the environment where it will be used. OpenAI's current ChatGPT capabilities, checked October 24, 2026.

Write a manually run VBA Sub for desktop Excel.
The code will be stored in the workbook it should modify.
Target only ThisWorkbook.Worksheets("Review").Range("D2:D6").

For each non-error cell, compare its trimmed text with "Blocked",
ignoring case. A match gets bold red text. Every other non-error
cell gets normal black text. Leave Excel error cells unchanged.
Do not change cell values, formulas, fills, borders, other font
properties, other ranges, or other worksheets.

Use Option Explicit and fully qualified references. Do not use
ActiveSheet, Selection, file/network access, shell commands, automatic
events, or changes to Excel security settings. If the target sheet
is absent, show an explanatory message and stop.

Return the complete code, explain every write operation, and provide
tests for mixed case, spaces, another status, blank, an Excel error,
a missing target sheet, and running while another sheet is active.
Do not claim the code was executed unless it actually was.

Inspect a complete procedure

This authored implementation illustrates that contract. It is not presented as a live ChatGPT answer or a macro executed in Excel during this guide's preparation.

Option Explicit

Public Sub MarkBlockedStatuses()
    Dim ws As Worksheet
    Dim cell As Range

    On Error Resume Next
    Set ws = ThisWorkbook.Worksheets("Review")
    On Error GoTo 0
    If ws Is Nothing Then
        MsgBox "Sheet Review was not found. No cells were changed."
        Exit Sub
    End If

    For Each cell In ws.Range("D2:D6").Cells
        If Not IsError(cell.Value2) Then
            If StrComp(Trim$(CStr(cell.Value2)), _
                       "Blocked", vbTextCompare) = 0 Then
                cell.Font.Bold = True
                cell.Font.Color = RGB(180, 0, 0)
            Else
                cell.Font.Bold = False
                cell.Font.Color = RGB(0, 0, 0)
            End If
        End If
    Next cell
End Sub

The only assignments to cells change Font.Bold and Font.Color inside the fixed range. ThisWorkbook refers to the workbook containing this code, so store the module in the intended workbook. A copy stored in a personal macro workbook would target that workbook instead.

Microsoft documents the range's Font object. Read any generated procedure for writes outside the stated range before inserting it. A request to preserve other cells is something to verify in the code and workbook.

Run a known fixture in a disposable workbook

Create a copy with a Review sheet. Enter these values in D2:D6:

Cell Input Expected after a run
D2 Blocked Bold red text
D3 blocked Bold red text; original spaces retained
D4 Done Normal black text
D5 Blank Normal black font settings
D6 Formula =NA() Error value and font unchanged

Put distinctive text and formatting in C2 and another worksheet. They should remain unchanged. Activate that other worksheet before running the procedure; the target should still be Review!D2:D6.

In desktop Excel, open Developer > Visual Basic, select the intended workbook in the project tree, and insert a standard module for the code. Run the named procedure manually. Save as .xlsm if you want to retain the macro; .xlsx does not retain it. Managed organizations may restrict macros, so use your approved workbook process. Microsoft's macro module instructions

Now change D2 from Blocked to Done and rerun. It should become normal black, demonstrating that the procedure clears its previous marking. Test a separate copy with the target sheet renamed: the procedure should report the missing sheet and leave cells unchanged. A protected sheet or other runtime error needs investigation before using the code in a working report.

If your task is a formula correction instead, the scoped Excel review guide covers that route. Keep the accepted macro beside its target description and test results, so the next person knows what it changes and which workbook should contain it.

Keep reading