+ Reply to Thread
Results 1 to 2 of 2

Multiple Select Drop Down, Alphabetically Sort Text in the Populated Cell

  1. #1
    Registered User
    Join Date
    09-01-2021
    Location
    Washington, DC
    MS-Off Ver
    2018
    Posts
    3

    Multiple Select Drop Down, Alphabetically Sort Text in the Populated Cell

    Hi Everyone!

    I am looking for help with the following problem. Please provide any code or suggestions:

    - I have created a multi-selection data validation drop down list for 2 columns in a worksheet of about 15 columns.
    - The text populated by the multi-selection drop down lists is separated by line breaks.
    - I would like each new selection from the drop down list to populate a single cell alphabetically. For example, if I select 'Operations' first from the drop down then select 'Certifications', I would like 'Certifications' to populate the cell before 'Operations'. Similarly, if I then select 'Audit' I would like 'Audit' to populate the cell before both 'Certifications' and 'Operations'.

    Here is my existing code that allows me to multi-select from a drop down, remove a selection, and separate the selections by a line break:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rngDV As Range
    Dim oldVal As String
    Dim newVal As String
    Dim lUsed As Long
    If Target.Count > 1 Then GoTo exitHandler

    On Error Resume Next
    Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
    On Error GoTo exitHandler

    If rngDV Is Nothing Then GoTo exitHandler

    If Intersect(Target, rngDV) Is Nothing Then
    'do nothing
    Else
    Application.EnableEvents = False
    newVal = Target.Value
    Application.Undo
    oldVal = Target.Value
    Target.Value = newVal
    Select Case Target.Column
    Case 6, 8
    If oldVal = "" Then
    'do nothing
    Else
    If newVal = "" Then
    'do nothing
    Else
    lUsed = InStr(1, oldVal, newVal)
    If lUsed > 0 Then
    If Right(oldVal, Len(newVal)) = newVal Then
    Target.Value = Left(oldVal, Len(oldVal) - Len(newVal) - 2)
    Else
    Target.Value = Replace(oldVal, newVal & vbNewLine, "")
    End If
    Else
    Target.Value = oldVal _
    & vbNewLine & newVal
    End If

    End If
    End If
    End Select
    End If

    exitHandler:
    Application.EnableEvents = True
    End Sub

  2. #2
    Registered User
    Join Date
    09-01-2021
    Location
    Washington, DC
    MS-Off Ver
    2018
    Posts
    3

    Post Re: Multiple Select Drop Down, Alphabetically Sort Text in the Populated Cell

    Found the answer using code provided in thread titled "pick multiple items from list and sort alphabetically in single cell"

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Pick multiple items from list and sort alphabetically in single cell
    By kawale in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-07-2021, 01:48 PM
  2. Replies: 6
    Last Post: 07-23-2021, 06:59 AM
  3. Replies: 9
    Last Post: 04-14-2020, 05:08 PM
  4. Sort alphabetically within a cell
    By DianaM in forum Excel General
    Replies: 2
    Last Post: 08-04-2017, 02:08 PM
  5. [SOLVED] Using an array formula to sort alphabetically over multiple columns
    By AliGW in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 02-14-2014, 02:13 PM
  6. Replies: 2
    Last Post: 08-01-2011, 08:45 AM
  7. Sort text list alphabetically using a formula
    By paddyyates in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-20-2005, 11:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1