使用列表validation单元格:应用程序定义的错误或对象定义的错误

我正在使用下面的代码将validation列表添加到各个单元格。 我觉得这很简单,但是我在Formula1:="Notes!A1" & finalRowNotes行发现一个错误。 错误是

应用程序定义或对象定义的错误

我错过了什么?

 finalRowNotes = Worksheets("Notes").Cells(1000000, 1).End(xlUp).Row For i = 4 To r - 1 With Range("P" & i).Validation .Delete .Add Type:=xlValidateList, _ AlertStyle:=xlValidAlertStop, _ Operator:=xlBetween, _ Formula1:="=Notes!A1:A" & finalRowNotes .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "" .InputMessage = "" .ErrorMessage = "" .ShowInput = True .ShowError = True End With Next i 

对于什么是值得的,这里是单元格A1:A18 Notes工作表中的内容

 Block volume not reported Blocks Blocks away Blocks. Foreign trades not incl. in volume or VWAP in this market Could not inventory Market closed No foreign trades Order canceled Order complete Order given after market Order given mid-session Out of limit Out of limit, changed to market order after session closed Out of limit-premium Pending 1 day funding requirement Pending custodian confirmation Volume out of limit Volume out of limit, limit reduced during session 

根据问题和第一个答案中的对话,我build议将下面的代码放在一个模块中:

 'Dimension your two variables Dim Notes As Worksheet, Vali As Worksheet 'Set the variables equal to the sheet names. Set Notes = Sheets("Notes") Set Vali = Sheets("NAME OF VALIDATION SHEET") 'Changes the Sheet reference to the variable Notes and changed your syntax to Rows.Count finalRowNotes = Notes.Cells(Rows.Count, 1).End(xlUp).Row 'Rows.Count is better method for last row of document For i = 4 To r - 1 'Added Vali to define the sheet With Vali.Range("P" & i).Validation .Delete .Add Type:=xlValidateList, _ AlertStyle:=xlValidAlertStop, _ Operator:=xlBetween, _ Formula1:="=Notes!A1:A" & finalRowNotes .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "" .InputMessage = "" .ErrorMessage = "" .ShowInput = True .ShowError = True End With Next i 

我不知道该说些什么,对于浪费大家的时间,我感到抱歉,但是当我把这个工作簿恢复到早期版本时,一切都很好。 我所能想到的只是感谢所有把帽子扔在戒指上的人,并且给予了这样的慷慨的努力。 我猜想我的工作簿不知何故被破坏了,因为一个更老,但是完全相同的工作正常。

你使用operator xlBetween。 我想,你需要xlEqual。

只要激活范围,它将解决问题..

 Vali.Range("P" & i).Activate