VBA Multiselect & Single select lists

ExcelHelpNeeded99

New Member
Joined
Oct 6, 2017
Messages
13
Can anyone help me see where Im going wrong. I only want multi select dropdown lists in columns 10,22,46,47,48, I need the rest to be single select or text only. I used the below vba code and altered it for my columns but every column is multi select. I am new to this forum and appreciate the help. Thanks

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    'Updated: 2016/4/12
    Dim xRng As Range
    Dim xValue1 As String
    Dim xValue2 As String
    
    If (Target.Column = 10 Or Target.Column = 22 Or Target.Column = 46 Or Target.Column = 47 Or Target.Column = 48) Then Exit Sub
    On Error Resume Next
    Set xRng = Cells.SpecialCells(xlCellTypeAllValidation)
    If xRng Is Nothing Then Exit Sub
    Application.EnableEvents = False
    If Not Application.Intersect(Target, xRng) Is Nothing Then
        xValue2 = Target.Value
        Application.Undo
        xValue1 = Target.Value
        Target.Value = xValue2
        If xValue1 <> "" Then
            If xValue2 <> "" Then
                If xValue1 = xValue2 Or _
                   InStr(1, xValue1, "; " & xValue2) Or _
                   InStr(1, xValue1, xValue2 & ";") Then
                    Target.Value = xValue1
                Else
                    Target.Value = xValue1 & "; " & xValue2
                End If
            End If
        End If
    End If
    Application.EnableEvents = True
End Sub
[Code/]
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try removing the bits of code in red (Exit Sub) , and then add an "End if" at the bottom of the code, just before "End Sub"
Code:
If (Target.Column = 10 Or Target.Column = 22 Or Target.Column = 46 Or Target.Column = 47 Or Target.Column = 48) Then [SIZE=3][B][COLOR=#FF0000]Exit Sub[/COLOR][/B][/SIZE]
 
Upvote 0
Hi Mick I tried that but now it made all dropdown columns single select instead of multi select for relevant columns ( i also updated column refs) ,any other ideas? Thanks

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Updated: 2016/4/12
Dim xRng As Range
Dim xValue1 As String
Dim xValue2 As String


If (Target.Column = 5 Or Target.Column = 17 Or Target.Column = 41 Or Target.Column = 42 Or Target.Column = 43) Then
On Error Resume Next
Set xRng = Cells.SpecialCells(xlCellTypeAllValidation)
If xRng Is Nothing Then Exit Sub
Application.EnableEvents = False
If Not Application.Intersect(Target, xRng) Is Nothing Then
xValue2 = Target.Value
Application.Undo
xValue1 = Target.Value
Target.Value = xValue2
If xValue1 <> "" Then
If xValue2 <> "" Then
If xValue1 = xValue2 Or _
InStr(1, xValue1, "; " & xValue2) Or _
InStr(1, xValue1, xValue2 & ";") Then
Target.Value = xValue1
Else
Target.Value = xValue1 & "; " & xValue2
End If
End If
End If
End If
Application.EnableEvents = True
End If
End Sub



[\Code]
 
Upvote 0
Thanks, your example is what I want, only thing is, my lookup values are in another tab and there are different lists for each column. How would I modify for that? I really appreciate the help!
 
Upvote 0
Just a note- I know how to update the data validation lists from the other tab its just the vba piece Im wondering how to tell it they are on another tab. Thanks
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,578
Members
449,174
Latest member
chandan4057

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