Data Validation error Message 'application or Object Defined Error

SJ-NY

Board Regular
Joined
Feb 16, 2008
Messages
156
Hi

I am using the following code to change the data validation source list based on the value in column "B"

It was working fine and then stopped. I get the error message at the lines;
.Add Type:=xlValidateList, Formula1:="=TempDescriptions"
.Add Type:=xlValidateList, Formula1:="=PermDescription"

Can anyone spot what is causing this problem.

Thanks

Steve

Application.EnableEvents = True
Select Case Target.Column
Case 1
With Selection
.Offset(, 1).FormulaR1C1 = "=RIGHT(RC[-1],9)"
.Offset(, 2).ClearContents
.Offset(, 5).ClearContents
End With
i = Selection.Row

'this section determines which list to use based on the the value in the cell in column "B"
If Cells(i, 2).Value = "Temporary" Then
With Cells(i, 3).Validation
.Delete

' Problem occurs here
.Add Type:=xlValidateList, Formula1:="=TempDescriptions"

End With
Else
With Cells(i, 3).Validation
.Delete

' Problem occurs here
.Add Type:=xlValidateList, Formula1:="=PermDescription"

End With
End If
End Select
Application.CutCopyMode = False
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Be sure the Defined Names exist. Be sure they are Global Defined Names, not Local to a particular worksheet.
 
Upvote 0
Hi:
That was the first thing I checked.

I noticed the problem was not consistent. I did further testing an realized the problem only occurred when the sheet was protected. Early on I thought that was the problem and I examined each cell to make sure it was not locked.

Once I removed the protection from the sheet it worked fine.

I am not sure why when the sheet was protected this problem happened. Luckily I was able to work around this, but I would like to know why it was happening.

Again thanks for your help

Steve
 
Upvote 0
It has been my experience that there are some things we try to do in VBA that will not work if Protection is turned on. When confronted with such a situation, the only way I know to figure it out is experimenting to see if that is the problem. If it is, you can put code into your procedure to turn protection off, do the changes, and turn protection back on.

There is a protection mode that allows VBA to make changes to protected cells but prevent users from doing so. Check out the UserInterfaceOnly property on the Worksheet.Protect method. Note though that UserInterfaceOnly must be set every time you open the workbook that you use it in. It is not saved when you save the workbook. Also, I don't know if it will be the solution you need, but it might. If so it will simplify what you have to do concerning Protection.
 
Upvote 0
Hi

Fortunately my application of worksheet protection was a little over zealous. The sheet where the problems were occurring does not need protection. Thank you for reminding me of the other method of handling this. After I complete this project I will try that method to see if it will prevent the error.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Again thank you for your help<o:p></o:p>
Steve<o:p></o:p>
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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