【问题标题】:Populating 2 listbox with diferent rows用不同的行填充 2 个列表框
【发布时间】:2018-08-23 11:01:45
【问题描述】:

我的用户窗体上有 1 个组合框和 2 个列表框:

  1. cbox_rrhh
  2. lbox_por
  3. lbox_done

还有一张这样的“Pedidos”表:

我找到了一种方法来过滤组合框值之后的列表框数据,该值是“J”列 ex(roraima,karla,yvonne,sara) 中的值,但我还需要在 lbox_por 上显示行如果是“否”,则列“J”与“Si”匹配,必须在 lbox_done 中加载这些行。

使用的代码:

    Private Sub cbo_rrhh_Change()
Dim Cell As Range                   'defining your searcharea
Dim Row_Counter As Integer          'rowno
Dim Pos As Integer                  'rowno in array
Dim MyList() As String              'the array
Dim No_Pos As Integer               'total rows in aray
Dim Search_name As String           'searchvalue in combobox
Dim Real_last_row As Integer        'last row in "Pedidos"

'xllastrow is a function

Real_last_row = xlLastRow("Pedidos") 'last row in "Pedidos"

Search_name = cbo_rrhh.Value

'Searching in "Pedidos" for matches with searchstring

For Each Cell In Worksheets("Pedidos").Range("J2:J" & Real_last_row)
    If Cell Like "*" & Search_name & "*" Then
'If a value matches with the searchstring, number of rows of array is + 1
        No_Pos = No_Pos + 1
    End If
Next Cell

Row_Counter = 2                  'start of the nameslist
Pos = 0                          'rowno in array, beginning with zero
ReDim Preserve MyList(No_Pos, 8) 'Redimming of array with total no of rows and 3 columns

'if value isn't in searchstring then rowno is rowno + 1
'if a match is found the array is filled and the rowno in array is + 1

For Each Cell In Worksheets("Pedidos").Range("J2:J" & Real_last_row)
    If Cell Like "*" & Search_name & "*" Then
        MyList(Pos, 0) = Worksheets("Pedidos").Range("A" & Row_Counter)
        MyList(Pos, 1) = Worksheets("Pedidos").Range("B" & Row_Counter)
        MyList(Pos, 2) = Worksheets("Pedidos").Range("C" & Row_Counter)
        MyList(Pos, 3) = Worksheets("Pedidos").Range("E" & Row_Counter)
        MyList(Pos, 4) = Worksheets("Pedidos").Range("F" & Row_Counter)
        MyList(Pos, 5) = Worksheets("Pedidos").Range("G" & Row_Counter)
        MyList(Pos, 6) = Worksheets("Pedidos").Range("H" & Row_Counter)
        MyList(Pos, 7) = Worksheets("Pedidos").Range("I" & Row_Counter)
        MyList(Pos, 8) = Worksheets("Pedidos").Range("J" & Row_Counter)
        Pos = Pos + 1
        Row_Counter = Row_Counter + 1
    Else
        Row_Counter = Row_Counter + 1
    End If
Next Cell
Application.ShowToolTips = True

With lbox_por
    .ColumnCount = 10                           'no of columns (0,1,2)
    .ControlTipText = "Pedidos pendientes ..."    'tiptext

End With
With lbox_done
    .ColumnCount = 9                           'no of columns (0,1,2)
    .ControlTipText = "Pedidos realizados ..."    'tiptext

End With
lbox_por.List = MyList                          'define the list of listbox1
lbox_done.List = MyList

End Sub

对于上下文: Fecha:意思是日期。 帕拉布拉斯:词。 塔萨:率。 蒙托:数量。 帕加多:付清了。 编辑:作家。

【问题讨论】:

    标签: vba excel filter listbox


    【解决方案1】:

    对于一个列表框(lbox_done),你不能改变吗:

    If Cell Like "*" & Search_name & "*" Then
    

    到这里:

    If Cell Like "*" & Search_name & "*" And Worksheets("Pedidos").Range("I" & Row_Counter) = "NO" Then
    

    然后您可以创建一个重复列表(即MyList2),并将条件更改为:

    If Cell Like "*" & Search_name & "*" And Worksheets("Pedidos").Range("I" & Row_Counter) = "SI" Then
    

    您可以将其分配给另一个列表框 -- lbox_por

    【讨论】:

      猜你喜欢
      • 2022-10-06
      • 1970-01-01
      • 2017-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-18
      相关资源
      最近更新 更多