Hi.
I grabbed a version of the following code from another forum (ozgrid, Dave Hawley/iwrk4dedpr) and tried to adapt it to my own spreadsheet. However, it seems as though the named ranges I want to delete do not always get deleted. There must be a problem with how I have the code grab the named range from each worksheet and delete the data validation in the named ranges: CostCenterValue and MonthOfRevenue. If anyone can see it or know why I might be having this problem, I would appreciate your help.
Private Sub Workbook_beforeclose(cancel As Boolean)
Dim ws As Worksheet
Dim rRangeCheck As Range
For Each ws In ActiveWorkbook.Worksheets
On Error Resume Next
Set rRangeCheck = ws.Range("CostCenterValue")
On Error GoTo 0
If rRangeCheck Is Nothing Then
Else
With ws
.Range("CostCenterValue").Validation.Delete
.Range("MonthOfRevue").Validation.Delete
End With
End If
Next
End Sub
I grabbed a version of the following code from another forum (ozgrid, Dave Hawley/iwrk4dedpr) and tried to adapt it to my own spreadsheet. However, it seems as though the named ranges I want to delete do not always get deleted. There must be a problem with how I have the code grab the named range from each worksheet and delete the data validation in the named ranges: CostCenterValue and MonthOfRevenue. If anyone can see it or know why I might be having this problem, I would appreciate your help.
Private Sub Workbook_beforeclose(cancel As Boolean)
Dim ws As Worksheet
Dim rRangeCheck As Range
For Each ws In ActiveWorkbook.Worksheets
On Error Resume Next
Set rRangeCheck = ws.Range("CostCenterValue")
On Error GoTo 0
If rRangeCheck Is Nothing Then
Else
With ws
.Range("CostCenterValue").Validation.Delete
.Range("MonthOfRevue").Validation.Delete
End With
End If
Next
End Sub