VBA Excelvalidation列表超过可变范围

我试过这段代码在Excel中设置一个validation列表。 我试图用variables来replace特定的单元格,但是我不能用固定单元格来解决这个问题。

谢谢。

With Selection.Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:="=Range(Cells(5, 15), Cells(6, 15))" .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "" .InputMessage = "" .ErrorMessage = "" .ShowInput = True .ShowError = True End With 

尝试这个:

  .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:= "=" & Range(Cells(5, 15), Cells(6, 15)).Address 

或这个:

  .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:= "=$O$5:$O$6"