简体   繁体   English

组合框列表中的动态范围

[英]Dynamic range in combobox list

I'm using two methods to build a dynamic list of names in the combo box row source. 我正在使用两种方法在组合框行源中构建动态名称列表。 In the first instance i use: 首先,我使用:

With Sheet2 与Sheet2

RateComboBox.RowSource = "'" & .Name & "'!" RateComboBox.RowSource =“'”&.Name&“'!” & .Range("b9", .Range("c33").End(xlUp)).Address End With &.Range(“ b9”,.Range(“ c33”)。End(xlUp))。地址结尾为

The control source is set to a cell on a sheet and the bound column is column 1, or the range b9:b33 which has the numbers 1-25 and the column count is 2 which the second column list names (1-25) as they are added. 控制源设置为工作表上的单元格,并且绑定的列为第1列,或者范围b9:b33的范围为数字1-25,列数为2,第二列列表名称为(1-25)他们被添加。 It works great until the range C9:C33 is full at which time the drop down list shows a bogus list with items (text) that start now in B1. 在范围C9:C33填满之前,它一直很好用,这时下拉列表显示一个伪造的列表,其中包含从B1开始的项目(文本)。 What is happening? 怎么了?

In the second instance I use: 在第二种情况下,我使用:

Me.ComboBox1.RowSource = Worksheets("Form").Range("B8", Range("B32").End(xlUp)).Address Me.ComboBox1.RowSource = Worksheets(“ Form”)。Range(“ B8”,Range(“ B32”)。End(xlUp))。Address

which the range b8:B32 is populated with names as they are added there. 其中在b8:B32范围内添加了名称。 the control source is set to a cell on a sheet and the bound column is column 1. Again it works great until the (list) range is full. 控制源设置为工作表上的单元格,装订的列为第1列。同样,它很好用,直到(列表)范围已满。 In both instances I only want items (names) in the combo box to be listed as they are added in those ranges. 在这两种情况下,我只希望列出组合框中的项目(名称),因为它们是在这些范围内添加的。 ?? ??

For the first part like this: 对于这样的第一部分:

If Len(.Range("c33").Value) Then
  RateComboBox.RowSource = "'" & .Name & "'!B9:C33"
Else
  RateComboBox.RowSource = "'" & .Name & "'!" & .Range("b9", .Range("c33").End(xlUp)).Address
End If

For the second part it is as good as the same: 对于第二部分,它也一样:

If Len(Range("B32").Value) Then
  Me.ComboBox1.RowSource = Worksheets("Form").Range("B8:B32").Address
Else
  Me.ComboBox1.RowSource = Worksheets("Form").Range("B8", Range("B32").End(xlUp)).Address
End If

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM