列表框值为Vlookup到组合框值

时间:2013-12-05 17:19:47

标签: combobox listbox vlookup userform

工作表:MASTER DATA

Column A = Engine.
Column B = Part Number.
Column C = Status.
Column D = Name.
Column E = Quantity.
Column F = Date.
Column G = Priority.
Column H = Buyer.

场合: 我手动输入A列到H列的所有数据。我创建了一个userform,用于输入从J列到M的数据。

在我的用户表单中

如果我在组合框中选择买方,我希望列表框中填充与该特定买方对应的工作表“MASTER DATA”中的所有partnumbers。我正在考虑将vlookup用于买方价值,然后可能抵消-6来获取partnumber值? 任何帮助表示赞赏。

到目前为止

我的代码:

Private Sub UserForm_Initialize()
    With cboBuyer
        .AddItem "DANIEL"
    End With
End Sub

Private Sub cboBuyer_Change()
    Me.lbPartNumber.Clear
    Select Case Me.cboBuyer.Value
        Case "DANIEL"
            With Me.lbPartNumber
                .AddItem "(VLOOKUP VALUES TO THE BUYER NAME (DANIEL)
            End With
    End Select
End Sub

1 个答案:

答案 0 :(得分:0)

解决方案

Private Sub cboBuyer_Change()

Dim i

Me.lbPartNumber.Clear

Dim lastrow As Long
lastrow = Sheets("MASTER DATA").Cells(Rows.count, "B").End(xlUp).Row

Select Case Me.cboBuyer.Value
    Case "DANIEL"
        With Me.lbPartNumber
            For i = 1 To lastrow   ' Rowcount
                Sheets("MASTER DATA").Activate
            If Cells(i, 8) = "DANIEL" Then
                .AddItem Cells(i, 2)
            End If
            Next i
        End With
    End Select