1

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.

我的问题是我似乎无法弄清楚如何让命令按钮也填充组合框。

.additem下面的代码不断返回

“权限被拒绝”错误

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

任何帮助将不胜感激。

4

1 回答 1

2

首先你需要检查RowSource你的组合框,如果它不是空的,清空它。

然后因为您只想拥有可见单元格(在自动过滤器之后);你需要使用Range("Tariffs").SpecialCells(xlCellTypeVisible).

这是您修改后的代码:

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

要在您的用户窗体控件上循环,请使用以下内容:

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
于 2015-11-12T15:18:10.387 回答