Automatically Insert an Excel Row When Yes Is Selected
Question details
Automatically insert a worksheet row when a user selects Yes from a Yes/No dropdown.

- 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.
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.
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.
In desktop Excel, right-click the relevant worksheet tab and select View 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
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.
Return to the worksheet and select Yes in B2. Excel should insert a new row 3 and move the existing row 3 downward.

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.

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.




