Excel – Can the data validation list width be controlled in Excel 2007 and greater

microsoft excelmicrosoft-excel-2007vba

In Excel 2007, I can add data validation to a cell, and supply a list of allowed values.

However, experimentation suggests that the data validation drop-down list will never display at a smaller width than the original width of its cell (at the point the workbook was opened).

So if the cell's column was too big and the user re-sized it, you end up with this sort of thing:

drop-down wider than the column

Is there any way to improve this? Can the drop-down width be made to match the column width without closing and re-opening the workbook? Writing some VBA is an option.

Best Answer

You're right, this can occur when you change the width after creating the dropdown, but also sometimes when there are merged cells present. VBA is the only option. Place this in the worksheet object and change the column number to the column your list is in:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Target.Count > 1 Then Exit Sub
   If Target.Column = 4 Then
       Target.Columns.ColumnWidth = 20
   End If
End Sub

It will look for changes in your list and adjust to the specified width.

Related Question