Error Using VBA Data Validation

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,616
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am getting an "Application-Defined or Object-Defined error with the line in red. Can anyone suggest a cause and solution to fix this? It's probably quite simple, but I just can't figure it out. The only thing I thought was that I can't redefine a previously defined name? That possibly its necessary to clear that name range of previous assignments before assigning a new range to it?

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim nr_func As Range
    Dim nr_leag As Range
    
    If Not mbevents Then Exit Sub
    
    If Target.Address = "$F$6" Then
        mbevents = False
        ws_form.Unprotect
        rcode = ws_form.Range("C6").Value
        'create ranges (nr_func) for named range based on rcode
        'diamonds
       
            If ws_form.Range("F6") = "Slopitch" Then
                MsgBox "Slopitch."
                Set nr_leag = ws_lists.Range("F2:F14")
            ElseIf ws_form.Range("F6") = "Baseball" Then
                MsgBox "Baseball."
                Set nr_leag = ws_lists.Range("F20:F30")
            ElseIf ws_form.Range("F6") = "Softball" Then
                MsgBox "Softball."
                Set nr_leag = ws_lists.Range("F33:F39")
            ElseIf ws_form.Range("F6") = "Fastball" Then
                MsgBox "Fastball"
                Set nr_leag = ws_lists.Range("F42:F47")
            ElseIf ws_form.Range("F6") = "Camp" Then
                MsgBox "Camp"
                Set nr_leag = ws_lists.Range("F160:F163")
            ElseIf ws_form.Range("F6") = "Special Event" Then
                MsgBox "Special Event"
                Set nr_leag = ws_lists.Range("F167:F171")
            'ElseIf ws_form.Range("F6") = "MISC. DIA. SPORTS" Then
            '    MsgBox "Misc. Diamond Sports"
            '     Set nr_leag = ws_lists.Range("F49:F52")
            Else
                MsgBox "Error"
                Stop
            End If
        End If
        
        'create named range (nr_funct) based on nr_func
        ActiveWorkbook.Names.Add Name:="nr_league", RefersTo:=nr_leag
        
        functn = ws_form.Range("F6").Value
        
        With ws_form.Range("f6")
            .Interior.Color = RGB(198, 244, 180)
            .Borders.Color = RGB(55, 86, 35)
        End With
        With ws_form.Range("K6")
            If .MergeCells = True Then
                Set mergeRange = .MergeArea
                mergeRange.Locked = False
            End If
            .Value = ""
            .Interior.Color = RGB(221, 235, 247)
            .Borders.Color = RGB(48, 84, 150)
            .Validation.Add Type:=xlValidateList, Formula1:="=nr_league"
            .Select
        End With
        ws_form.Protect
        mbevents = True
    End If

    If Target.Address = "$K$6" Then
        mbevents = False
        ws_form.Unprotect
    End If
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I found my error. I had the data validation also set at the worksheet level. Once I cleared it things were good.
 
Upvote 0

Forum statistics

Threads
1,224,835
Messages
6,181,245
Members
453,026
Latest member
cknader

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top