Note that there are some explanatory texts on larger screens.

plurals
  1. POExcel 2010 VBA Formula1 Referencing a Named Range *or* cell location with variable for tab name
    text
    copied!<p>In VBA (Excel 2010), I am </p> <ol> <li>dynamically creating a named range list</li> <li>using that list to create drop down choices in another column</li> </ol> <p>When creating the drop down list, (a) using the named range doesn't seem to work, and (b) if I don't use the named range - and need to reference by sheet name and cell reference, I get into trouble because my sheet has just been renamed with today's date.</p> <p>This is messy, I know, but here is what I have so far:</p> <pre><code>' 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 &amp; "!R3C37:R5C37") '~~&gt; Creates the list With Range("K2:K" &amp; 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 </code></pre> <p>The recorded macro when I created the named region made sense enough:</p> <pre><code>ActiveWorkbook.Names.Add Name:="StageListChoices", RefersToR1C1:= _ "=2013-JAN-24!R3C37:R14C37" ActiveWorkbook.Names("StageListChoices").Comment = "" </code></pre> <p>Originally, I had been creating the drop down in VBA with a String variable, but the "real" list is 15 items long and I was getting errors upon reopening the file that the validation had been too long (?) and so had been turned off. </p> <p>Basically, I've tried things like:</p> <pre><code>Formula1:="=StageListChoices" Formula1:=vRangeName Formula1:="=vRangeName" Formula1:=vTabDateName &amp; "!R3C37:R5C37" </code></pre> <p>Everything I've looked up says that the first one (Formula1:="=StageListChoices") should have worked - but it doesn't.</p> <p>Thank you!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload