VBA excel - 如果组合框

时间:2017-11-22 03:31:42

标签: excel vba excel-vba combobox listbox

我遇到了一些vba的问题。我有一个列表框(lb_lease)和一个组合框(cbox_hardware),它由命名范围填充(都有3列:名称,数量,价格< / strong>),也是一个按钮,可以将组合框中的新项目添加到列表框中。

目前在我的代码中,如果组合框的值与列表框中的项目匹配,则不会添加另一个项目,如果该值不存在于列表中,则会添加该项目。

如果组合框(第一列名称)的值与列表框列表中的任何项目匹配(第一列名称),我希望如此,它会增加列表框中该特定行的数量列,但不会添加其他项。

我对此非常陌生并感到有点迷失这个,任何帮助都不仅仅是值得赞赏! 提前致谢

What it currently looks like

How I would like it to function

下面的添加按钮的代码
Dim f As Integer
Dim i As Integer
Dim Exists As Boolean

Exists = False

For f = 0 To Me.lb_lease.ListCount - 1

   If Me.lb_lease.Column(0, f) = cbox_hardware.Value Then
      Exists = True
   Else
   End If

Next f

    If Exists = True Then

 'Code to increment selected row that exists in combo box

    ElseIf Exists = False Then

       With Me.lb_lease
       .ColumnCount = 3
       .ColumnWidths = "200;50;50"
       .AddItem
       .List(.ListCount - 1, 0) = cbox_hardware.Column(0)
       .List(.ListCount - 1, 1) = cbox_hardware.Column(1)
       .List(.ListCount - 1, 2) = cbox_hardware.Column(2)
       i = i + 1
       End With

    End If

0 个答案:

没有答案