简体   繁体   中英

getting the drop down value in the change event of the same dropdown not as a message box but as a string in excel VBA

I have a drop down in Excel which has a link to a cell depending on a list of values(string format) in another sheet. while changing the drop down i need the value selected (and not the index) as a string in the VBA code for further use.

I have searched and found that it can be shown as a msgbox, but i need it in the VBA code for further use in the code.

how can i get this value.

Thanks

If you have a Forms-type dropdown (not ActiveX), then you could can use the ListFillRange and Value properties to get the value selected. The Value property returns the position in the list and the ListFillRange property is a string representation of the range.

Sub GetListFillRangeSelection()

    Dim dd As DropDown
    Dim rInput As Range
    Dim sSelected As String

    Set dd = Sheet1.DropDowns(1)
    Set rInput = Range(dd.ListFillRange)

    sSelected = rInput.Cells(dd.Value, 1).Value

    Debug.Print sSelected

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM