验证列表 - 无法将“formula1”中另一个工作表中的范围作为变量引用

时间:2015-11-10 16:04:12

标签: vba excel-vba excel

   Set AcctRng = Sheets("New Accounts").Range(Cells(2, 1),Cells(countnonblank1 + 1, 1))
   CntNBlnk = Application.WorksheetFunction.CountA(AcctRng)

   Set MasterSht = ThisWorkbook.Worksheets("Master Data")
   LstRo = MasterSht.Cells(MasterSht.Rows.Count, "A").End(xlUp).Row

 '  Sheets("New Accounts").Range("a5") = LstRo

   Set ChoiceRng = Sheets("Master Data").Range(Cells(4, 1), Cells(LstRo, 1))
   'Sheets("Master Data").Range(Cells(4, 1), Cells(LstRo, 1))


 '  Choice = "ChoiceRange"


     Sheets("New Accounts").Range(Cells(2, 2), Cells(CntNBlnk + 1, 2)).Select
     With Selection.Validation
    .Delete
   .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
     xlBetween, Formula1:=ChoiceRng
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With

所有变量都是相应声明的,验证列表代码中的formula1部分是否有一些引用问题?

1 个答案:

答案 0 :(得分:0)

  

,验证列表代码中的formula1部分是否存在一些refrencing问题?

是:ChoiceRng是一个对象。明确使用.Address属性:

.Add Type:=xlValidateList, _
     AlertStyle:=xlValidAlertStop,  _
     Operator:=xlBetween, _
     Formula1:=ChoiceRng.Address