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

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

问题描述

我有用于库存控制的用户表单,用于进出项目,我想做的就是修改以下代码以在其代码旁边显示每个项目名称以进行搜索项目.代码:

私有子 ComboBox1_Click()Dim i 作为整数将 j 调暗为整数Dim final 作为整数Dim FINAL2 作为整数对于 i = 2 到 1000如果 Hoja5.Cells(i, 1) = "" 那么最终 = i - 1退出万一下一个对于 i = 2 到 1000如果 Hoja6.Cells(i, 1) = "" 那么最终 2 = i - 1退出万一下一个对于 i = 2 到最终如果 ComboBox1 = Hoja5.Cells(i, 1) 那么TextBox1 = Hoja5.Cells(i, 2)退出万一下一个对于 j = 1 到 FINAL2如果 ComboBox1 = Hoja6.Cells(j, 1) 那么TextBox8 = Hoja6.Cells(j, 3)退出万一下一个结束子私有子 ComboBox1_Enter()Dim i 作为整数将 j 调暗为整数将 H 调暗为整数Dim final 作为整数Dim tareas As StringComboBox1.BackColor = &H80000005对于 i = 1 到 ComboBox1.ListCountComboBox1.RemoveItem 0接下来我对于 j = 2 到 1000如果 Hoja5.Cells(j, 1) = "" 那么最终 = j - 1退出万一下一个对于 H = 2 到最终tareas = Hoja5.Cells(H, 1)ComboBox1.AddItem (tareas)下一个'万一结束子

表明需要修改的照片

我希望它是这样的:

示例文件

  • 通过 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天全站免登陆