+ Reply to Thread
Results 1 to 3 of 3

A dynamical dropdown list which autoupdates and autosorts alphabetically

Hybrid View

  1. #1
    Registered User
    Join Date
    09-09-2024
    Location
    india
    MS-Off Ver
    2019
    Posts
    2

    A dynamical dropdown list which autoupdates and autosorts alphabetically

    I have an excel Sheet1, with cell B6 containing data validation. The range is in Sheet2, column A from Cells A2-A100.
    Here is my question, I wish to enter a value in cell B6, which contains the data validation list options as they are in Sheet2.
    Is there a way I can enter a new value in cell B6 which is not in the dropdown list of Sheet 2? So that I do not get an error message and the dropdown list in Sheet2 will get auto updated by that new value and will be automatically sorted alphabetically.
    I hope I am clear with my query.
    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,699

    Re: A dynamical dropdown list which autoupdates and autosorts alphabetically

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim res, lr As Long, ws As Worksheet
    If Not Intersect(Target, Range("B6")) Is Nothing Then
        Application.EnableEvents = False
        Call ADD_DVlist(Target)
        Range("B6").Validation.Delete
        Range("B6").Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
        Formula1:="=DV_List"
    End If
    Application.EnableEvents = True
    End Sub
    Insert in Sheet1 module: righ click on tab, "View code", copy/past code

    In standard module

    Option Explicit
    
    Sub ADD_DVlist(tValue)
    Dim res, lr As Long, ws
    
        res = Application.Match(tValue, Range("DV_LIST"), 0)
        If IsError(res) Then                ' New entry so update DV List
            Set ws = Sheets("sheet2")
            With ws
                lr = .Cells(Rows.Count, "A").End(xlUp).Row + 1
                .Cells(lr, 1) = tValue
                .Range("A1:A" & lr).Sort Key1:=.Range("A1"), Order1:=xlAscending, Header:=xlNo
          End With
        End If
    
    End Sub
    to add new names, simply type in B6
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Registered User
    Join Date
    09-09-2024
    Location
    india
    MS-Off Ver
    2019
    Posts
    2

    Re: A dynamical dropdown list which autoupdates and autosorts alphabetically

    Thanks for the help. I solved my problem.
    regards

+ 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. Replies: 6
    Last Post: 01-20-2024, 08:32 PM
  2. Replies: 1
    Last Post: 10-14-2021, 11:47 AM
  3. Replies: 5
    Last Post: 11-15-2018, 11:02 AM
  4. [SOLVED] Macro that autosorts
    By Brandmire in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-21-2015, 07:36 AM
  5. Dropdown list that lets you sort teh worksheet via a sertain coloum (alphabetically)?
    By joshnathan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-24-2012, 02:39 AM
  6. Replies: 21
    Last Post: 12-02-2009, 03:27 PM
  7. Date dropdown list and a Time dropdown list in outlook
    By L_ter in forum Outlook Programming / VBA / Macros
    Replies: 3
    Last Post: 03-30-2009, 02:33 AM

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