Skip to content

Instantly share code, notes, and snippets.

@huvanile
Created August 8, 2022 20:23
Show Gist options
  • Save huvanile/706004bd146f97a16fe53fa82d8a283c to your computer and use it in GitHub Desktop.
Save huvanile/706004bd146f97a16fe53fa82d8a283c to your computer and use it in GitHub Desktop.
Example of how to programatically create a long drop-down list in Excel
Sub Macro4()
'longVal is collectively more than 255 characters
Dim longVal As String: longVal = "Lorem,ipsum,dolor,sit,amet,consectetur,adipiscing,elit.,Fusce,dolor,dui,eleifend,in,blandit,ac,,vulputate,ac,purus.,In,sollicitudin,dolor,at,massa,interdum,vulputate.,Etiam,eu,bibendum,elit.,Lorem,ipsum,dolor,sit,amet,consectetur,adipiscing,elit.,Fusce,dolor,dui,eleifend,in,blandit,ac,vulputate,ac,purus."
With ActiveSheet.Range("a1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=longVal
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment