Add single-letter headings in Excel drop down, so it's easier to find items in a long list. Use data validation and optional macros to add and remove headings.
Thanks to Roger Govier who created the original sample file for this technique, before Excel had named tables!
Drop Down Letter HeadingsFor data validation drop downs with a long list of items, add letter headings, to make navigation easier. This short video shows the steps, and there are written steps below the video. NOTE: People will be able to select the single letter headings in the drop down list, as well as the other items. That might cause problems in some workbooks How to Use Drop-Down List with HeadingsTo use the drop down, follow these steps:
To set up the letter headings:
|
In the sample workbook, there are 2 main sheets:
On the List sheet, there is an Excel table named tblProducts, with list of product names, sorted A-Z.
On the Data Entry sheet, there is an Excel table named tblData.
To see how to set up a named Excel table, watch this short video. There are written steps on the Excel Tables page. |
To see how to make a drop down list in a cell, watch the steps in this short video, and the written instructions are on the Excel Drop Down List page. |
This macro, named RemoveLetters, removes all single-character items in the named range, MyList, on the List sheet.
To use this macro in your own workbook, change the sheet name and table name in the code.
Sub RemoveLetters() Application.ScreenUpdating = False Dim wsL As Worksheet Dim myList As ListObject Dim rng As Range Dim rngDB As Range Dim c As Range Dim i As Long Dim lCells As Long Dim lRow As Long Dim lRowHead As Long Set wsL = Worksheets("List") Set myList = wsL.ListObjects("tblProducts") Set rng = myList.DataBodyRange.Columns(1) Set rngDB = myList.DataBodyRange lRowHead = myList.HeaderRowRange.Row lCells = rng.Cells.Count For i = lCells To 1 Step -1 Set c = rng.Cells(i, 1) If Len(c.Value) = 1 Then rngDB.Rows(c.Row - lRowHead).Delete End If Next i On Error GoTo 0 Application.ScreenUpdating = True End Sub
This macro, named InsertLettersAll, adds all 26 letters as headings in the named range, MyList, on the List sheet.
To use this macro in your own workbook, change the sheet name and table name in the code.
Sub InsertLettersAll() Application.ScreenUpdating = False RemoveLetters Dim wsL As Worksheet Dim myList As ListObject Dim rng As Range Dim rngDB As Range Dim c As Range Dim RowAdd As Long Dim lRow As Long Set wsL = Worksheets("List") Set myList = wsL.ListObjects("tblProducts") Set rngDB = myList.DataBodyRange With rngDB RowAdd = .Rows(.Rows.Count).Row End With For lRow = 1 To 26 wsL.Cells(RowAdd + lRow, 1).Value _ = Chr(lRow + 64) Next lRow Set rng = rngDB.Columns(1) rng.Sort Key1:=Range("A1"), _ Order1:=xlAscending, _ Header:=xlYes Application.ScreenUpdating = True End Sub
This macro, named InsertLettersUsed, adds letter headings in the named range, MyList, on the List sheet. It only add a letter if at least one product name begins with that letter.
To use this macro in your own workbook, change the sheet name and table name in the code.
Sub InsertLettersUsed() RemoveLetters Application.ScreenUpdating = False Dim wsL As Worksheet Dim myList As ListObject Dim rngDB As Range Dim rng As Range Dim c As Range Dim RowAdd As Long Dim lCells As Long Dim i As Long Dim lRow As Long Dim lRowHead As Long Set wsL = Worksheets("List") Set myList = wsL.ListObjects("tblProducts") lRowHead = myList.HeaderRowRange.Row Set rngDB = myList.DataBodyRange With rngDB RowAdd = .Rows(.Rows.Count).Row End With For lRow = 1 To 26 wsL.Cells(RowAdd + lRow, 1).Value _ = Chr(lRow + 64) Next lRow 'reset the range Set rngDB = myList.DataBodyRange Set rng = rngDB.Columns(1) lCells = rng.Cells.Count rng.Sort Key1:=rng.Cells(i, 1), _ Order1:=xlAscending, _ Header:=xlYes For i = lCells To 1 Step -1 Set c = rng.Cells(i, 1) If Len(c.Value) = 1 Then If Left(c.Offset(1, 0).Value, 1) <> c.Value Then rngDB.Rows(c.Row - lRowHead).Delete End If End If Next i Application.ScreenUpdating = True End Sub
To see the sample data and letter heading macros from this page, get the Letter Headings in Drop Down List.
The zipped file is in xlsm format, and contains the macros shown on this page, to add and remove letter headings.
Data Validation Drop Down List
Last updated: November 17, 2022 10:33 AM