Default value of Combobox(form control) VBA

余生长醉 提交于 2020-01-06 10:54:14

问题


Hey I have been searching a lot on the internet but I haven't been able to find the solution. I have atleast 10-15 combobox(form control) in my workbook. I want them to display a default value of say "Select type". Now, I have tried doing this using the ".listindex" but then it doesn't allow me to change the value in the combobox(as the default is set permanently).

Can someone help? This is what I tried to use

With ws(1).shapes("Chill1").controlformat
 .listindex = 1
End with

回答1:


The default state of the Combobox would be blank, so if anything needs to be put in, it'll usually be an item from the list range.

e.g. the input range (from Properties) is

    A1:A10

and the cell link is

    B1

Then B1 can be manually or through a macro (workbook_open event) set to value: 1

    Private Sub Workbook_Open()
        Worksheets("Sheet1").Range("B1") = 1
    End Sub

and A1 can contain the string 'Select Type'

That way everytime the workbook is opened, the macro sets the 1st values of each of these lists to "Select Type"



来源:https://stackoverflow.com/questions/24475537/default-value-of-comboboxform-control-vba

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