+ Reply to Thread
Results 1 to 2 of 2

Editing Code: Selecting multiple items in a cell via data validation

  1. #1
    Registered User
    Join Date
    08-03-2012
    Location
    fresno, ca
    MS-Off Ver
    Excel 2007
    Posts
    10

    Editing Code: Selecting multiple items in a cell via data validation

    The below code allows me to select multiple items in a cell and separates these items by a comma: However, it only allows me this option for data validation in column 3 ("C"). I am needing assistance on how to allow this code the same validation rule for, let's say columsn 3, 7, and 8? I've also attached the excel document to better illustrate what I would like to do.


    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 = 3 Then
    If oldVal = "" Then
    'do nothing
    Else
    If newVal = "" Then
    'do nothing
    Else
    Target.Value = oldVal _
    & ", " & newVal
    End If
    End If
    End If
    End If

    exitHandler:
    Application.EnableEvents = True
    End Sub
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    03-17-2012
    Location
    Warsaw, Poland
    MS-Off Ver
    2007/2010
    Posts
    555

    Re: Editing Code: Selecting multiple items in a cell via data validation

    please use
    Please Login or Register  to view this content.
    If you think that my answer was helpful, please click on the "Add to this user's Reputation" button.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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