Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,616
- Office Version
- 365
- 2016
- Platform
- 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