Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Validation list default value

Is there a way to have a default value appear from a validation list when it gets created in VBA? So far I have:

.Cells(j, 7).Validation.Add Type:=xlValidateList, Formula1:="=" & "Listname"
like image 790
KingKong Avatar asked Nov 05 '25 12:11

KingKong


1 Answers

Sure. Just explicitly set the cell's value after you add its validation rule :)

Dim defaultValue as String 'string right?
defaultValue = ... 'get the value you want from your [ListName]

.Cells(j, 7).Validation.Add Type:=xlValidateList, Formula1:="=" & "Listname"       
.Cells(j, 7).Value = defaultValue
like image 169
Mathieu Guindon Avatar answered Nov 08 '25 13:11

Mathieu Guindon