Several variants.
You can put data validation data in a cell, rather than a Dropdown object. This returns the actual results, not the index. If you still need a separate linked cell, you can put a formula that just copies the dv cell
Sub MakeDv() Dim wSheet As Worksheet Dim myRng As Range Set wSheet = ActiveSheet Set myRng = wSheet.Cells(row, col) myRng.Validation.Add xlValidateList, , , "msg1,msg2" wSheet.Cells(row, col + 2).Formula = "=" & myRng.Address End Sub
Another option is to not use the LinkedCell property and use a macro to write the value. Assign this macro to the drop-down list.
Sub ShowDDResult() Dim dd As DropDown Set dd = ActiveSheet.DropDowns(Application.Caller) ActiveSheet.Cells(row, col + 2).Value = dd.List(dd.Value) End Sub
It may not be so simple if you create a worksheet from scratch from Access, because you will need to add a macro. The final option is to use the ListFillRange property to populate the drop-down list. Put the list in the range and use the formula with LinkedCell to deduce the date from the list.
Sub testdd() Dim wSheet As Worksheet Dim myRng As Range Dim myDD As DropDown Dim rList As Range Dim aList(1 To 2, 1 To 1) As String Set wSheet = ActiveSheet Set rList = wSheet.Range("D1:D2") Set myRng = wSheet.Cells(row, col) aList(1, 1) = "msg1": aList(2, 1) = "msg2" rList.Value = aList With myRng Set myDD = .Parent.DropDowns.Add(Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height) myDD.ListFillRange = rList.Address myDD.LinkedCell = wSheet.Cells(row, col + 2).Address wSheet.Cells(row, col + 3).Formula = "=INDEX(" & rList.Address & "," & myDD.LinkedCell & ",1)" End With End Sub
source share