不需要在工作表中粘贴值来创建下拉列表.看这个例子
Option Explicit
Sub Sample()
Dim dvList As String
'~~> You can construct this list from your database
dvList = "Option1, Option2, Option3"
'~~> Creates the list in Sheet1, A1
With Sheets("Sheet1").Range("A1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=dvList
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8329 次 |
| 最近记录: |