Created
February 5, 2015 23:04
-
-
Save walkergv/2535e708bab419d0551f to your computer and use it in GitHub Desktop.
Create a multiselect excel macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' | |
' taken from the website for instructions http://www.contextures.com/excel-data-validation-multiple.html | |
Option Explicit | |
Private Sub Worksheet_Change(ByVal Target As Range) | |
Dim rngDV As Range | |
Dim oldVal As String | |
Dim newVal As String | |
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 | |
If Target.Column = 12 Then | |
If oldVal = "" Then | |
'do nothing | |
Else | |
If newVal = "" Then | |
'do nothing | |
Else | |
Target.Value = oldVal _ | |
& ", " & newVal | |
' NOTE: you can use a line break, | |
' instead of a comma | |
' Target.Value = oldVal _ | |
' & Chr(10) & newVal | |
End If | |
End If | |
End If | |
End If | |
exitHandler: | |
Application.EnableEvents = True | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment