【发布时间】:2015-10-31 14:16:20
【问题描述】:
以下是我的excel的代码
通过宏创建多个依赖项时,出现错误
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=indirect("A" & i)"
仍在试图弄清楚如何将范围值传递到公式部分
Sub listing()
Dim cellv As Range
For i = 3 To 10000
Set cella = Sheet1.Range("A" & i)
With cella.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=Main"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Invalid Input"
.InputMessage = ""
.ErrorMessage = "Select the location only from the dropdown list."
.ShowInput = False
.ShowError = True
End With
Set cellb = Sheet1.Range("B" & i)
With cellb.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=indirect("A" & i)"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Invalid Input"
.InputMessage = ""
.ErrorMessage = "Select the location only from the dropdown list."
.ShowInput = False
.ShowError = True
End With
Next
End Sub
【问题讨论】:
-
此部分格式错误:
Formula1:="=indirect("A" & i)"。它应该类似于Formula1:="=A" & i,但这没有多大意义,因为您只是说它应该与同一行中的 A 列具有相同的值。你的意图是什么?当您在单个单元格上设置数据验证时录制宏时的代码是什么样的? -
我想要多个依赖项...它将从第一个单元格中获取值并为子列表提供一个下拉列表...我希望这几乎是 1000 个单元格。通过使用 for 循环,我可以获得 1000 个单元格,但我无法将 i 变量的范围传递给 Formula1:="=indirect("A" & i)"
-
没有人可以帮我解决这个问题吗?
标签: excel excel-formula excel-2010 excel-2007 vba