向vba用户窗体组合框添加两列 [英] adding two columns to vba userform combobox

查看:210
本文介绍了向vba用户窗体组合框添加两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有用于​​进出物品的库存控制用户表单,我要做的就是修改以下代码以在其代码旁边显示每个物品名称以进行搜索。
代码:

  Private Sub ComboBox1_Click()

以整数
Dim j作为整数
Dim最终作为整数
Dim FINAL2作为整数

对于i = 2到1000
如果Hoja5.Cells(i,1)= 那么
final = i-1
退出
如果
结束,则

For i = 2到1000
如果Hoja6.Cells (i,1)=然后
FINAL2 = i-1

退出如果
下一个

为i = 2到最终
如果ComboBox1 = Hoja5.Cells(i,1)然后
TextBox1 = Hoja5.Cells(i,2)

退出如果
下一个

对于j = 1到最终2
如果ComboBox1 = Hoja6.Cells(j,1)然后
TextBox8 = Hoja6.Cells(j,3)
退出
如果
下一个

结束,则结束


Private Sub ComboBox1_Enter()
Dim i As Integer
Dim j Integer
Dim H作为整数
Dim最终作为Integer
Dim tareas作为String

ComboBox1。 BackColor =& H80000005

对于i = 1到ComboBox1.ListCount
ComboBox1.RemoveItem 0
接下来的i

对于j = 2至1000
如果Hoja5.Cells(j,1)=然后
final = j-1
退出
结束如果
下一个

对于H = 2到最后
tareas = Hoja5.Cells(H,1)
ComboBox1.AddItem(tareas)
Next
'End if

结束Sub

照片指示所需的修改





我希望它像这样:





示例文件




  • 设置第二个列值由 ComboBox1.Column(1,{rowIndex}) ='the value'`。在您的代码中。



    对于i = 2到最终
    tareas = Hoja5.Cells(i,1)
    ComboBox1.AddItem(tareas
    '-设置第一列
    ComboBox1.Column(1,i-2)= Hoja5.Cells(i,2)'名称
    下一步



  • i have that userform for stock control which used to in or out items, all i want to do to amend the below code to show each item name beside it`s code to make searching items. Code:

    Private Sub ComboBox1_Click()
    
    Dim i As Integer
    Dim j As Integer
    Dim final As Integer
    Dim FINAL2 As Integer
    
    For i = 2 To 1000
        If Hoja5.Cells(i, 1) = "" Then
            final = i - 1
            Exit For
        End If
    Next
    
    For i = 2 To 1000
        If Hoja6.Cells(i, 1) = "" Then
            FINAL2 = i - 1
            Exit For
        End If
    Next
    
    For i = 2 To final
        If ComboBox1 = Hoja5.Cells(i, 1) Then
            TextBox1 = Hoja5.Cells(i, 2)
            Exit For
        End If
    Next
    
    For j = 1 To FINAL2
        If ComboBox1 = Hoja6.Cells(j, 1) Then
            TextBox8 = Hoja6.Cells(j, 3)
            Exit For
        End If
    Next
    
    End Sub
    
    
    Private Sub ComboBox1_Enter()
    Dim i As Integer
    Dim j As Integer
    Dim H As Integer
    Dim final As Integer
    Dim tareas As String
    
    ComboBox1.BackColor = &H80000005
    
    For i = 1 To ComboBox1.ListCount
        ComboBox1.RemoveItem 0
    Next i
    
    For j = 2 To 1000
        If Hoja5.Cells(j, 1) = "" Then
            final = j - 1
            Exit For
        End If
    Next
    
    For H = 2 To final
        tareas = Hoja5.Cells(H, 1)
        ComboBox1.AddItem (tareas)
    Next
    'End If
    
    End Sub
    

    photo indicating the required amendment

    I want it to be like:

    sample file

    download sample for the above userform

    解决方案

    To do this:

    1. Set the ColumnCount = 2 for ComboBox

    2. Set the 2nd column value by ComboBox1.Column(1,{rowIndex}) = 'the value'`. In your code. it should be like:

      For i = 2 To final tareas = Hoja5.Cells(i, 1) ComboBox1.AddItem (tareas) '-- set the first column ComboBox1.Column(1, i - 2) = Hoja5.Cells(i, 2) 'the name Next

    这篇关于向vba用户窗体组合框添加两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆