VBA & Macro Problems

Automatically Insert an Excel Row When Yes Is Selected

Bushra ParveenBushra Parveen Nov 18, 2026 869 views

Question details

Automatically insert a worksheet row when a user selects Yes from a Yes/No dropdown.

Automatically Insert an Excel Row When Yes Is Selected
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet uses data validation to let users select Yes or No, and a Yes selection should trigger a new row.
Observed behavior
Excel formulas cannot insert worksheet rows when the dropdown value changes.
Before you start

Identify the dropdown cell and where the new row should be inserted. The example below uses cell B2 and inserts row 3; adjust both references for your worksheet.

Solution 1Recommended

Use a VBA worksheet event to insert a row

Use this method in desktop Excel when selecting Yes in a specific cell should immediately insert a row.

A Worksheet_Change event runs when a user changes the watched cell. The example inserts a row each time B2 is changed to Yes; it does not run when a formula recalculates.

1
Open the worksheet code

In desktop Excel, right-click the relevant worksheet tab and select View Code.

2
Add the event code

Paste this code into the worksheet's code window, changing B2 and row 3 as needed: Private Sub Worksheet_Change(ByVal Target As Range) If Target.CountLarge <> 1 Then Exit Sub If Intersect(Target, Me.Range("B2")) Is Nothing Then Exit Sub If IsError(Target.Value2) Then Exit Sub If LCase$(Trim$(CStr(Target.Value2))) <> "yes" Then Exit Sub On Error GoTo CleanUp Application.EnableEvents = False Me.Rows(3).Insert Shift:=xlDown CleanUp: Application.EnableEvents = True End Sub

3
Save as a macro-enabled workbook

Choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm). When reopening a trusted workbook, select Enable Content if Excel prompts you to enable macros.

4
Test the dropdown

Return to the worksheet and select Yes in B2. Excel should insert a new row 3 and move the existing row 3 downward.

Use a VBA worksheet event to insert a row
Adjust the behavior for your workbook: This example does not explicitly copy formulas or values into the inserted row. If you need those copied, or need a row inserted beside each changed dropdown, the event code must be adapted to your worksheet layout.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format compatibility, making it easy to move everyday spreadsheet work between applications. Excel VBA automation may require different support or adjustments in WPS.

Edit spreadsheets in a familiar, easy-to-use interfaceOpen and work with Microsoft Excel XLSX filesReview Yes/No dropdowns and worksheet data in a spreadsheet applicationUse a lightweight office suite for everyday document work
microsoft office alternative - wps office

Frequently Asked Questions

Can an Excel formula insert a row when I select Yes?

No. Formulas return values but cannot insert worksheet rows. Use an event-driven method such as a VBA Worksheet_Change macro instead.

Where do I put the VBA code?

In desktop Excel, right-click the worksheet tab containing the dropdown, select View Code, and paste the event procedure into that worksheet's code window.

Why does the workbook need to be saved as XLSM?

The Excel Macro-Enabled Workbook format preserves VBA code. Use File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm); recipients must enable macros for the event to run.

Will the example insert another row every time I choose Yes?

Yes. Each time B2 changes to Yes, the example inserts a new row 3. Selecting No does not insert a row.

Will the VBA event run in Excel for the web?

No. Excel for the web does not run VBA macros. Open the macro-enabled workbook in desktop Excel and enable macros if you trust the file.