自动根据组合框更改txtbox值 [英] automatically Change txtbox value accourding to combobox

查看:65
本文介绍了自动根据组合框更改txtbox值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sheet1的"A"列中有一些员工姓名,在"B"列中有一些员工编号.在用户窗体上,我有一个显示员工姓名的组合框,我想要在组合框上选择一个姓名时,在附近的txtbox上显示他/她的员工编号,而我不知道该怎么做.

I have some employee Names on column "A" and employee Numbers on column "B" in sheet1. On userform I have a combobox that shows employee names,i want when a name is selected on combobox his/her employee Number shown on a nearby txtbox and i dont know how.

Me.cboNames
Me.txtEmployeeNumber

推荐答案

此代码有效

Private Sub cboName_Change() '<-- your combobox
    Dim EName As String
    Dim Row As Integer
    EName = Me.cboName.Text
    If EName <> "" Then
        With Application.WorksheetFunction
            Row = .Match(EName, Sheets("sheet1").Range("A2:A100"), 0) '< your combobox data worksheet and range 
            txtEmployeeNumber.Text = .Index(Sheets("sheet1").Range("B2:B100"), Row) '< your textbox data worksheet and range

        End With
    End If
End Sub

这篇关于自动根据组合框更改txtbox值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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