+ Reply to Thread
Results 1 to 6 of 6

VBA stopped working!!

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-30-2008
    Location
    Los Angeles
    Posts
    144

    VBA stopped working!!

    Yesterday I received great help from everyone on the code below. It worked perfectly allowing me to select more than one item in a drop down.

    Today it stopped working. I had copied the file with a new name and changed the target column to 14 (Column N) and it did not work.

    I went back to the original file with column 10 and it does not work either. Any ideas would be appreciated.....thanks again Max
    -----------------------------------------------------
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim sOld    As String
        Dim sNew    As String
        Dim rVal    As Range
    
        If Target.Column <> 14 Then Exit Sub
    
    
        On Error Resume Next
        Set rVal = Me.Cells.SpecialCells(xlCellTypeAllValidation)
        If rVal Is Nothing Then Exit Sub
        On Error GoTo 0
    
        If Not Intersect(Target, rVal) Is Nothing Then
            Application.EnableEvents = False
            sNew = Target.Value
            Application.Undo
            sOld = Target.Value
    
            If Len(sNew) = 0 Then
                Target.ClearContents
            ElseIf Len(sOld) = 0 Then
                Target.Value = sNew
            Else
                Target.Value = sOld & ", " & sNew
            End If
    
            Application.EnableEvents = True
        End If
    End Sub
    Last edited by maxthebear; 02-18-2009 at 09:51 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA stopped working!!

    It only works for cells in col 14 that have data validation.

    You also took out the test for target.count > 1, which will result in a runtime error if multiple cells with validation are changed simultaneously.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    10-30-2008
    Location
    Los Angeles
    Posts
    144

    Re: VBA stopped working!!

    Thank you. Where exactly would the target.count >1 go in the code along with the target column <> 14. thanks much.

    Max

  4. #4
    Forum Contributor
    Join Date
    10-30-2008
    Location
    Los Angeles
    Posts
    144

    Re: VBA stopped working!!

    OK how does this look?? It still doesn't seem to work...I made column N a validation...

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim sOld    As String
        Dim sNew    As String
        Dim rVal    As Range
    
        If Target.Column <> 14 Then Exit Sub
         If Target.Count > 1 Then Exit Sub
    
        On Error Resume Next
        Set rVal = Me.Cells.SpecialCells(xlCellTypeAllValidation)
        If rVal Is Nothing Then Exit Sub
        On Error GoTo 0
    
        If Not Intersect(Target, rVal) Is Nothing Then
            Application.EnableEvents = False
            sNew = Target.Value
            Application.Undo
            sOld = Target.Value
    
            If Len(sNew) = 0 Then
                Target.ClearContents
            ElseIf Len(sOld) = 0 Then
                Target.Value = sNew
            Else
                Target.Value = sOld & ", " & sNew
            End If
    
            Application.EnableEvents = True
        End If
    End Sub
    Last edited by maxthebear; 02-18-2009 at 08:05 PM. Reason: Added a line

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA stopped working!!

    Does the cell you're changing have validation?

    Have you closed and reopened Excel to make sure events are enabled?

    If yes to both of the above, post the workbook again, Max.

  6. #6
    Forum Contributor
    Join Date
    10-30-2008
    Location
    Los Angeles
    Posts
    144

    Re: VBA stopped working!!

    I got out of Excel and back in and it worked. thanks again. I'll post it as solved.........

    Max

+ 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