简体   繁体   English

根据文本框值搜索列,并在列表框中显示所有结果

[英]Seach Column based on textbox value and display all results in Listbox

I have a 我有一个

ListBox = firmList; 
TextBox = firmGroupID; 
Worksheet = RelatedFirms; 
ColumnA = gID (ID numbers); 
ColumnB = firmName 

I am trying to populate my list box based on the value of firmGroupID. 我试图根据firmGroupID的值填充列表框。
Currently I have a combobox that populates the gID number in firmGroupID depending on combobox selection. 目前,我有一个组合框,它根据组合框的选择填充firmGroupID中的gID号。

I would then like the firmList to populate with the list of firmNames based on the firmGroupID. 然后,我希望firmList填充基于firmGroupID的firmNames列表。

Sheet RelatedFirms contains the assigned gID for each firmName. 工作表RelatedFirms包含为每个firmName分配的gID。

This seems simple but everything I try doesn't seem to work. 这似乎很简单,但我尝试的所有方法似乎均不起作用。

Not sure how to only show items in list box that have the value that equals gID. 不确定如何仅显示列表框中具有等于gID的值的项目。

Private Sub firmGroupID_Change()
    Dim rngName As Range
    Dim ws As Worksheet
    Dim i As Integer

    Set ws = Worksheets("RelatedFirms")
    For i = 1 To ws.Cells(ws.Rows.Count, 1).End(xlUp).Row Step 1
        If ws.Cells(i, 1).Value <> vbNullString Then Me.firmList.AddItem
        ws.Cells(i, 1).Value   
        Next i
End Sub

Please change this code: 请更改此代码:

If ws.Cells(i, 1).Value <> vbNullString Then Me.firmList.AddItem ws.Cells(i, 1).Value

To

If ws.Cells(i, 1).Value = firmGroupID.Value Then Me.firmList.AddItem ws.Cells(i, 2).Value   

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

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