log*_*gan 12 excel vba excel-vba
我有一系列的价值观.我想使用VBA在Excel Cell中显示这些值作为下拉列表.
这是我的代码.它显示" 类型不匹配错误! "
Dim xlValidateList(6) As Integer
xlValidateList(1) = 1
xlValidateList(2) = 2
xlValidateList(3) = 3
xlValidateList(4) = 4
xlValidateList(5) = 5
xlValidateList(6) = 6
With Range("A1").Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=ValidationList
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Run Code Online (Sandbox Code Playgroud)
问题发生在以下行...
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
Run Code Online (Sandbox Code Playgroud)
请告诉我问题所在...提前致谢
Sea*_*anC 30
您正在将数组定义为xlValidateList(),因此当您尝试分配类型时,会对您尝试分配给类型的内容感到困惑.
相反,试试这个:
Dim MyList(5) As String
MyList(0) = 1
MyList(1) = 2
MyList(2) = 3
MyList(3) = 4
MyList(4) = 5
MyList(5) = 6
With Range("A1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=Join(MyList, ",")
End With
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
127214 次 |
| 最近记录: |