Need List Box values to be displayed in cell after clicked

核能气质少年 提交于 2020-01-06 03:34:04

问题


I have a Form Control list box with multiple iteams. I would like a certain cell on the spreadsheet to display the contents of the list box item the user selects and change if the user makes a different selection.

Not sure where to even start with this.


回答1:


I guess you already know how to write to a cell:

Set TxtRng = ActiveWorkbook.Sheets("YourSheet").Range("A1")
TxtRng.Value = "Your Text Here"

And the following piece of code would go into your ListBoxChanged-Event, so the cell displays the new value every time a new value has been selected in the List Box.

For i = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(i) Then
        SelectedItemText = ListBox1.List(i)
    End If
Next i
'Set the value of the cell to the selected item.
TxtRng.Value = SelectedItemText 

Hope this helps.



来源:https://stackoverflow.com/questions/22836577/need-list-box-values-to-be-displayed-in-cell-after-clicked

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!