Multi-select from data validation isn't working in conjunction with auto-assigning data validation

iPenguin

New Member
Joined
Sep 11, 2017
Messages
4
I have a sheet within my workbook where I'm trying to do a couple related things at once that I think may be messing with each other. [FONT=&quot]I am applying data validation on the fly first -- in other words, every time I click on a cell in a given range on my sheet "User Lists" it checks the header of that column, looks for that value in the header row on "User Picklists" and then if it finds it it uses the list from that page as the list for data validation on User Lists. Some of the columns need to be Multi-Select though, so once that code block runs, I have included code that I found on this page. (I also tried the code on this page with the same result.)

For the Multi-Select portion, I copied the code almost exactly from the post above (I only altered the initial If statement to match my actual use case). The difference between my sheet and the sample sheet is that the sample sheet fires the code when you select a value from the list (expected behavior), but my sheet fires it right when I click the cell. I am guessing this is because of the first code block that assigns the data validation. That code block is a necessary part of the sheet's functionality, so removing it isn't an option, but what I am looking to discover is how I can make the second half of this code (the multi select) fire only when selecting a value from the list.

Code:
[/FONT][/COLOR]<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=000000]#000000[/URL] ; background-color: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ffffff]#ffffff[/URL] }p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; background-color: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ffffff]#ffffff[/URL] ; min-height: 13.0px}span.s1 {color: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=011993]#011993[/URL] }</style>[/FONT][/COLOR]
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=000000]#000000[/URL] ]Application.ScreenUpdating = [/COLOR]False


    Dim ws As Worksheet
    Dim RefRng As Range, RngFind As Range, NewRng As Range, hdr
    Dim RefList As Range, c As Range, rngHeaders As Range, Msg


    On Error GoTo ErrHandling


    Set ws = ThisWorkbook.Worksheets("User Picklist")


    'only deal with the selected cell(s)
    Set NewRng = Application.Intersect(Me.Range("A12:T101"), Target)
    If Not NewRng Is Nothing Then


        Set rngHeaders = ws.Range("A11:ZZ11")


        For Each c In NewRng
            c.Validation.Delete 'delete previous validation
            hdr = Me.Cells(11, c.Column).Value


            If Len(hdr) > 0 Then
                Set RngFind = rngHeaders.Find(hdr, , xlValues, xlWhole)
                'matched header?
                If Not RngFind Is Nothing Then


                    Set RefList = ws.Range(RngFind.Offset(1, 0), _
                                           RngFind.Offset(1, 0).End(xlDown))


                    c.Validation.Add Type:=xlValidateList, _
                                     AlertStyle:=xlValidAlertStop, _
                                     Formula1:="='" & ws.Name & "'!" & RefList.Address


                End If 'matched header
            End If 'has header


        Next c
    End If 'in required range


'Multi Select
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Not NewRng Is Nothing Then
  If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
    GoTo Exitsub
  Else: If Target.Value = "" Then GoTo Exitsub Else
    Application.EnableEvents = False
    Newvalue = Target.Value
    Application.Undo
    Oldvalue = Target.Value
      If Oldvalue = "" Then
        Target.Value = Newvalue
      Else
        If InStr(1, Oldvalue, Newvalue) = 0 Then
            Target.Value = Oldvalue & ", " & Newvalue
      Else:
        Target.Value = Oldvalue
      End If
    End If
  End If
End If




Here:
    Application.ScreenUpdating = True


Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True


    Exit Sub


ErrHandling:
    If Err.Number <> 0 Then
        Msg = "Error # " & Str(Err.Number) & " was generated by " & _
            Err.Source & Chr(13) & "Error Line: " & Erl & Chr(13) & Err.Description
        Debug.Print Msg, , "Error", Err.HelpFile, Err.HelpContext
    End If
    Resume Here
    
[COLOR=#242729][FONT=Arial][COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=011993]#011993[/URL] ][FONT=Menlo]End[/FONT][/COLOR][FONT=Menlo] [/FONT][COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=011993]#011993[/URL] ][FONT=Menlo]Sub
[/FONT][/COLOR][COLOR=#2A2E2E][FONT=&quot]
[/FONT]

<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 ; background-color: #ffffff }p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; background-color: #ffffff ; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008f00 ; background-color: #ffffff }p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993 ; background-color: #ffffff }p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 ; background-color: #ffffff ; min-height: 13.0px}span.s1 {color: #011993 }span.s2 {color: #000000 }span.s3 {color: #008f00 }</style>
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,223,719
Messages
6,174,089
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top