Самый простой способ сделать выпадающий список DV - это строка , разделенная запятыми . Например:
Sub InternalString()
With Range("B2").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="alpha,beta,gamma,delta"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
, и мы можем сделать строку из диапазона, внутреннего массива VBA или коллекции:
Sub DVfromCollection()
Dim c As Collection
Set c = New Collection
c.Add "Larry"
c.Add "Moe"
c.Add "Curley"
'*********************************************************
Dim s As String
For i = 1 To c.Count
s = c.Item(i) & IIf(s = "", "", ",") & s
Next i
With Range("C2").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=s
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub