+ Reply to Thread
Results 1 to 6 of 6

Code not running properly! Getting error message

Hybrid View

  1. #1
    Registered User
    Join Date
    01-18-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    5

    Code not running properly! Getting error message

    I am trying to make a multi value picklist so when a user selects more than one option from the drop down menu, the results show in one cell separated by commas. I found this code online and plugged it into VB on my spreadsheet and it's not working. I'm not a coding expert so I don't know what the solution is. See code below:

    Sub DataMultiSelect()
    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
          End If
        End If
      End If
    End If
    
    exitHandler:
      Application.EnableEvents = True
    End Sub
    
    End Sub
    Last edited by arlu1201; 01-28-2013 at 01:29 PM. Reason: Added code tags.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Code not running properly! Getting error message

    Remove this line from your code -
    Sub DataMultiSelect()
    . This is line 1 and remove the End Sub at the end. You need to have only 1 End Sub.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    01-18-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Code not running properly! Getting error message

    Now VB is not recognizing my macro since I took out the first line.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Code not running properly! Getting error message

    Once you remove the top line, what you get is a worksheet event macro. Hence you need to select on your sheet containing the data, right click and select "View Code" and then copy the code in there. As soon as you change the dropdown values, the macro will start working as desired.

  5. #5
    Registered User
    Join Date
    01-18-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Code not running properly! Getting error message

    Thank you! I got it to work!

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Code not running properly! Getting error message

    Based on your last post in this thread, its apparent that you are satisfied with the solution(s) you've received and have solved your question, but you haven't marked your thread as "SOLVED". I will do it for you this time.

    In future, to mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.

+ 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