Excel VBA: Autofit Rows After Multiple Drop-Down Selections
Question details
Adjust an Excel Worksheet_Change macro so combined data validation selections wrap and the affected row fits the text.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet macro combines multiple selections from a data validation drop-down in one cell.
- Observed behavior
- The combined text does not display correctly within the row.
Locate the existing Worksheet_Change procedure for the worksheet and identify where it assigns the combined selection to the changed cell. Confirm that the target cells are not merged, because Excel AutoFit does not reliably adjust row height for merged cells.
Wrap the combined value and autofit the changed row
Use this fix in the existing multi-selection macro after it assigns the combined value to the cell.
Keep the existing code that combines drop-down selections; data validation alone does not provide multiple selections. Add the row-height commands to the same Worksheet_Change procedure rather than creating a second procedure with that name.
In Excel, open Developer > Visual Basic. In the project pane, double-click the worksheet that contains the drop-down and find its Worksheet_Change procedure.
Before the macro changes the cell value, add `On Error GoTo CleanUp` and `Application.EnableEvents = False`. If the procedure already has an error handler or cleanup label, adapt that handler instead of adding a duplicate.
Immediately after the existing assignment of the combined value, add: Target.WrapText = True Target.EntireRow.AutoFit Keep these lines within the part of the macro that handles the intended drop-down cell.
Before `End Sub`, add a cleanup section so events are restored even if an error occurs: CleanUp: Application.EnableEvents = True If the procedure already has a cleanup section, add the event-restoration line there instead.
Return to the worksheet and select several items from the data validation drop-down. Check that the combined text wraps and that the row height expands.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for opening and editing Excel files. Its format compatibility makes moving everyday spreadsheet work straightforward, but it does not repair an Excel VBA event macro, and macro compatibility can vary.

Frequently Asked Questions
Where should I put the AutoFit command?
In the worksheet's existing Worksheet_Change procedure, place `Target.WrapText = True` and `Target.EntireRow.AutoFit` immediately after the macro assigns the combined selection to the cell.
Why should the macro disable events?
Writing a combined value to the cell can trigger Worksheet_Change again. Set `Application.EnableEvents = False` before the write, then restore it to `True` in the procedure's cleanup section.
Why does AutoFit still not change the row height?
Merged cells can prevent Excel from automatically fitting row height. Unmerge the affected cells or use Home > Format > Row Height to set the height manually.
Does Excel data validation allow multiple selections by itself?
A standard data validation drop-down selects one value at a time. Keep the existing VBA logic that combines selections, and add the wrap and AutoFit commands after its combined-value assignment.
What if worksheet events stop working after I test the macro?
In the Visual Basic Editor, open View > Immediate Window, enter `Application.EnableEvents = True`, and press Enter. Then check that the macro restores events in its cleanup section.




