Results 1 to 9 of 9

Merging 2 VBA Codes

Threaded View

  1. #1
    Registered User
    Join Date
    11-02-2010
    Location
    Los Angeles
    MS-Off Ver
    Ms Excel 2010
    Posts
    6

    Merging 2 VBA Codes

    Hi Guys,

    I'm new to VBA coding, so please bare with me

    I want to implement multiple selections within several drop down list, after googling and searching here and there i managed to find the following coding lines which work great in any given column:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rngDV As Range
    Dim oldVal As String
    Dim newVal As String
    Dim lUsed As Long
    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 = 9 Then
        If oldVal = "" Then
          'do nothing
          Else
          If newVal = "" Then
          'do nothing
          Else
            lUsed = InStr(1, oldVal, newVal)
            If lUsed > 0 Then
                If Right(oldVal, Len(newVal)) = newVal Then
                    Target.Value = Left(oldVal, Len(oldVal) - Len(newVal) - 2)
                Else
                    Target.Value = Replace(oldVal, newVal & ", ", "")
                End If
            Else
                Target.Value = oldVal _
                  & ", " & newVal
            End If
            
          End If
        End If
      End If
    End If
    
    exitHandler:
      Application.EnableEvents = True
    End Sub
    Now, The issue is that I want the multiple selection to apply to at least 2 Columns, I've tried several combinations wit If/End if/Else & Else If, and after cleaning up I seem to disable the loop effect,

    Can anyway help?

    kindest regards!

    Cruz
    Last edited by arlu1201; 04-23-2013 at 11:37 AM. Reason: Use code tags in future.

Thread Information

Users Browsing this Thread

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

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