首页 > 解决方案 > excel vba listbox additem

问题描述

I am running office 365 home on windows 10. I am programming Excel using VBA. I have a data range in a worksheet row. I want the user to be able to select one item from this row of data. I am trying to populate ListBox or ComboBox with dta from the range row. Having read MS vba.reference documentation I decided to get my range data into an array and use listbox = myarray() and got "Object does not support this method or property." I tried looping through my data range and putting each item in using listbox.additem (mydata()) with the same result. On examination of the listbox prperties AddItem is not there. Seems they have been withdrawn or maybe never existed for Excel VBA. Any suggestions?

标签: excelvbalistbox

解决方案


如果您使用的是 Additem,那么您应该只添加一个项目而不是一个数组。如果要使用数组,则必须使用 List 并且数组应该是一维的

MyListBox.List=MyOneDArray

就我个人而言,我从不使用 .List 和带有 Listboxes 的数组,因为我发现在某些情况下它不能按预期工作。


推荐阅读