Contact

Microsoft Excel · Automation bounded introductory track · Intermediate

Edit and debug one recorded VBA routine

Edit one range in a self-recorded VBA macro, pause with a breakpoint, and step through the change without lowering macro security.

Official documentation reviewed; synthetic fixtures checked independently; not executed in Excel · Editorial standards

Quick answer: Open your own recorded macro through Developer > Macros > Edit, change one range reference, and use a breakpoint plus Debug > Step Into to inspect execution. Test in a disposable workbook and keep a saved original: stepping through code still performs its actions.

Prepare a known recording

Use English Excel for Microsoft 365 desktop on Windows with Visual Basic Editor available and your existing policy permitting your own local macros. Do not import a sample macro workbook or change Trust Center protections. If execution is blocked, stop rather than weakening security settings.

Create a sheet named Practice. Enter Amount in B1 and 10,20,30,40,50 in B2:B6. Put =SUM(B2:B6) in D2; expect 150. Save a backup. Record a macro named BoldAmounts in This Workbook: while recording, explicitly select B2:B5 and apply bold, then stop recording. This gives you a short, user-owned routine whose purpose you already understand.

Save in XLSM format. The editing exercise starts from that recording; it does not require arbitrary copied VBA. The range selection should be visible in the generated code as Range("B2:B5").Select or an equivalent clearly identifiable fixed reference. Reject a relative recording using Offset/Resize for this exercise; a fixed address is the prerequisite for the one-address edit below. If your recording contains unrelated operations, discard it and rerecord the short sequence before editing.

Make one reviewable change

  1. Choose Developer > Macros, select BoldAmounts in this workbook, and choose Edit.
  2. Read the entire routine in Visual Basic Editor. Locate the statement selecting B2:B5 and the later statement applying bold.
  3. Change only the range address from B2:B5 to B2:B6. Keep quotes and parentheses intact. Leave the procedure name and other generated statements unchanged.
  4. Note what this edit means before running it: the fifth amount will now be included. No value, formula, file, or network operation should have been added.

This is a bounded range edit, not a general VBA programming tutorial. A successful compile or lack of red syntax coloring does not establish that the selected sheet is correct. A recorded unqualified Range normally acts relative to the active sheet, so ensure Practice is active before testing.

Pause and step through the routine

Outside recording, return to Practice and remove bold from B2:B6. In the editor, place the cursor on the range-selection statement and press F9 to toggle a breakpoint, or use Debug > Toggle Breakpoint. Start the routine. Execution should pause before that statement executes.

Choose Debug > Step Into or press F8 to execute one statement at a time. After the range-selection statement runs, inspect Excel: B2:B6 should be selected. Step through the formatting statement and check that all five amounts become bold. Continue only until the short procedure has finished. Remove the breakpoint when done.

The expected output is formatting across B2:B6 and an unchanged D2 total of 150. B1 should not be made bold by this edited range unless it was already formatted separately. If you pause on a line, remember that the highlighted next statement has not necessarily executed yet.

Use a changed input and preserve the result

Change B6 from 50 to 60 after the macro completes. D2 becomes 160. Remove bold, rerun the edited routine on Practice, and verify the same five-cell formatting with the new 160 total. This proves the routine formats existing values rather than rewriting the original recorded numbers.

Save the XLSM, close, and reopen. Inspect the edited range in the routine and test only under existing approved policy. If the macro affects the wrong sheet or range, stop and restore the backup; macro actions are not safely reversible through ordinary Undo. For the numerical control, see SUM.

Official references