Excel 2010 VBA Formula1引用名称范围*或*单元格位置与variables的选项卡名称

在VBA(Excel 2010)中,我是

  1. dynamic创build一个命名的范围列表
  2. 使用该列表在另一列创build下拉select

当创build下拉列表时,(a)使用命名的范围似乎不起作用,(b)如果我不使用命名的范围 – 并且需要通过表格名称和单元格引用来引用,那么我会遇到麻烦因为我的工作表刚刚被重新命名为今天的date。

我知道这很乱,但是到目前为止,

' find the name of the worksheet and replace it with today's date Dim vTabOriginalName As String Dim vTabDateName As String Dim vRangeName As String vRangeName = "StageListChoices" vTabOriginalName = ActiveSheet.Name vTabDateName = Format(Now(), "yyyy-mmm-dd") ActiveSheet.Name = vTabDateName 'create a drop down list for the stage (col K) Range("AK3").Value = "NO ACTIVITY" Range("AK4").Value = "SOLICITATION" Range("AK5").Value = "OPPORTUNITY" ActiveWorkbook.Names.Add Name:="StageListChoices", RefersToR1C1:=(vTabDateName & "!R3C37:R5C37") '~~> Creates the list With Range("K2:K" & vReportRowCount).Validation 'report row count known earlier .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=StageListChoices" .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "" .InputMessage = "" .ErrorMessage = "" .ShowInput = True .ShowError = True End With 

我创build命名区域时logging的macros已经足够了:

 ActiveWorkbook.Names.Add Name:="StageListChoices", RefersToR1C1:= _ "=2013-JAN-24!R3C37:R14C37" ActiveWorkbook.Names("StageListChoices").Comment = "" 

最初,我一直在使用Stringvariables在VBA中创build下拉列表,但是“真实”列表长度为15个项目,在重新打开validation文件太长(?)的文件时出现错误,closures。

基本上,我已经尝试过这样的事情:

 Formula1:="=StageListChoices" Formula1:=vRangeName Formula1:="=vRangeName" Formula1:=vTabDateName & "!R3C37:R5C37" 

我查过的所有东西都说第一个(Formula1:=“= StageListChoices”)应该可以工作 – 但事实并非如此。

谢谢!

更改

ActiveWorkbook.Names.Add Name:="StageListChoices", RefersToR1C1:=(vTabDateName & "!R3C37:R5C37")

ActiveWorkbook.Names.Add Name:="StageListChoices", RefersToR1C1:=("='" & vTabDateName & "'!R3C37:R5C37")

你错过了='