[英]Excel VBA ComboBox error
I am trying to fill a comboxbox located in sheet "AAA" with data in Sheet "BBB" 我正在尝试使用工作表“ BBB”中的数据填充工作表“ AAA”中的组合框
x = Application.WorksheetFunction.Max(Sheets("BBB").Range("m2:m200")) + 1
Sheets("AAA").Shapes("Drop_Leg").Select
With Selection
.ListFillRange = "='BBB'!n2:n" & x
End With
I am getting the error 我收到错误
"Requested Shapes are locked for selection". “锁定所需的形状以供选择”。
I have tried different approaches, but cannot get it to work. 我尝试了不同的方法,但无法使其正常工作。 This used to be a dropbox, but I was asked to change it to a combo. 这曾经是一个保管箱,但我被要求将其更改为组合。
Thanks in advance 提前致谢
Try the code below to populate your Active-X Combo-Box
. 尝试使用下面的代码填充Active-X Combo-Box
。
There's no need to use Select
to populate the Combo-Box
, it only slows down your code's run-time. 无需使用Select
来填充Combo-Box
,它只会减慢代码的运行时间。
Code 码
Option Explicit
Sub FillCombo()
Dim x As Long
Dim ComboRng As Range
x = Application.WorksheetFunction.Max(Sheets("BBB").Range("M2:M200")) + 1
Set ComboRng = Sheets("BBB").Range("N2:N" & x) '<-- set the Range
With Sheets("AAA").OLEObjects("Drop_Leg").Object
.Clear ' clear before adding new values
.List = ComboRng.Value ' populate the list with values from Column N
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.