gpt4 book ai didi

excel - 属性 "RowSource"无法在组合框中显示

转载 作者:行者123 更新时间:2023-12-04 20:37:49 24 4
gpt4 key购买 nike

如果我设置 .RowSource ListBox 的属性到 命名范围 然后在用户窗体的 VBA 显示和用户窗体的 Excel 显示中都可以选择行源。但是,使用 ComboBox 时,我只能在 VBA 显示屏上看到它。如果在设置 .RowSource 之后我尝试的属性(property).AddItem到我得到的 ComboBox 对象 run time error 70, permission denied .

Private Sub UserForm_Initialize()
With pres_unit
.AddItem "kPa"
.AddItem "bar"
End With
End Sub

如何使用命名范围作为 ComboBox 下拉选项的来源?

Excel screenshot of UserForm

VBA screenshot of UserForm

最佳答案

如果您使用的是 NamedRange对于单个列,您可以使用 List 的属性(property)组合框 :

Private Sub UserForm_Initialize()      

' create the Named Range "myNameRange"
' you can manually (or with variables) modify the Range("B2:B10") in "Sheet1"
ThisWorkbook.Names.Add "myNameRange", Sheets("Sheet1").Range("B2:B10")

With pres_unit
.List = Range("myNameRange").value
'disallows user input, only values from list
.Style = fmStyleDropDownList
End With

End Sub

关于excel - 属性 "RowSource"无法在组合框中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39304165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com