使用VBA在Excel ComboBox中动态设置ListFillRange [英] Dynamically set ListFillRange in Excel ComboBox using VBA

查看:2034
本文介绍了使用VBA在Excel ComboBox中动态设置ListFillRange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过如下操作:

  cmbMyBox.ListFillRange =E2

但是组合框似乎没有填充。好的,不要再来回答自己的问题了,但是Excel中的组合框中的ListFillRange属性绝对是令人生畏的。这是我实现的最终代码。

  Sheet1.Range(E3)。CurrentRegion.Select 
Dim example作为范围
设置示例=选择

带有cmbMyBox
.ListFillRange = example.Address(0,0,x1A1,True)
结束

这里的麻烦是我试图动态设置组合框,使用动态范围,这取决于用户输入的值是给出。据我所知,我不能使用命名范围,因为命名范围是固定的,例如(A3:Z20),无法调整。


I tried doing something like:

 cmbMyBox.ListFillRange = "E2"

But the combobox does not seem to populate.

解决方案

Ok, don't mean to answer my own question again but this ListFillRange property on combobox for Excel was absolutely maddening. Here's the final code that I implemented.

   Sheet1.Range("E3").CurrentRegion.Select
   Dim example as Range
   Set example = Selection

   With cmbMyBox
     .ListFillRange = example.Address(0, 0, x1A1, True)
   End With

The trouble here was that I was trying to dynamically set the combobox using a dynamic range which changes depending on what user inputted values were given. As far as I understand I couldn't use a named range because named ranges are FIXED, e.g (A3:Z20) and cannot be adjusted.

这篇关于使用VBA在Excel ComboBox中动态设置ListFillRange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆