简体   繁体   English

为组合框创建.additem

[英]Creating .additem for combobox

I have got a list of tariffs that i have set up on an autofilter so that when a specific sales channel is selected and password is correct it shows only the tariffs available to that channel. 我有一个在自动筛选器上设置的关税清单,以便在选择特定的销售渠道并且密码正确时,它仅显示该渠道可用的关税。

My problem is that I cant seem to figure out how to get the command button to also populate the combobox. 我的问题是我似乎无法弄清楚如何获取命令按钮来填充组合框。

my .additem code below keeps returning a 我下面的.additem代码不断返回

"Permission Denied" error “权限被拒绝”错误

Dim TLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("Tariff Matrix")
Set TLoc = Range("Tariffs")

For Each TLoc In ws.Range("Tariffs")
    With MobilePricing.Tariff1
        .AddItem TLoc.Value
    End With
Next TLoc

Any assistance will be greatly appreciated. 任何帮助将不胜感激。

First you need to check the RowSource of your ComboBox, if it's not empty, empty it. 首先,您需要检查ComboBox的RowSource ,如果不为空,请将其清空。

Then as you want to have only the visible cells (after the autofiler); 然后,您只想看到可见的单元格(在自动文件管理器之后); you need to use Range("Tariffs").SpecialCells(xlCellTypeVisible) . 您需要使用Range("Tariffs").SpecialCells(xlCellTypeVisible)

Here is your amended code : 这是您修改后的代码:

Dim TLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("Tariff Matrix")
Set TLoc = Range("Tariffs")

For Each TLoc In ws.Range("Tariffs").SpecialCells(xlCellTypeVisible).Cells
    With MobilePricing.Tariff1
        .AddItem TLoc.Value
    End With
Next TLoc

To loop on your UserForm Controls, use something like this : 要循环使用用户窗体控件,请使用以下代码:

Dim Ctrl As Control

For Each Ctrl In Me.Controls
    If TypeName(Ctrl) <> "ComboBox" Then 
    Else
        MsgBox Ctrl.Object.Name
        'Your code for one combobox (everyone will be referenced as Ctrl)
    End If
Next Ctrl

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

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