Excel Visual Basic ComboBox-TextBox与2个不同的单元格链接

时间:2019-01-21 07:32:07

标签: excel vba

我有1个与Cell链接的ComboBox(A195:1230)[Purchasing_Group_List_CO]和1个与Cell(B195:B230)[PIC_Name]链接的TextBox。我只想更改ComboBox上的值,然后TextBox将跟随其余的内容。但是我不知道我需要哪种语法来缩短这段代码。

我是这个领域的新手,试图了解VBA

这是我的代码。

Private Sub Purchasing_Group_List_CO_Change()

    If Purchasing_Group_List_CO.Value = "I10" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B195").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I20" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B196").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I21" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B197").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I22" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B198").Value)
    End If
     If Purchasing_Group_List_CO.Value = "I30" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B199").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I31" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B200").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I32" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B201").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I40" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B202").Value)
    End If
     If Purchasing_Group_List_CO.Value = "I41" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B203").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I42" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B204").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I50" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B205").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I51" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B206").Value)
    End If
     If Purchasing_Group_List_CO.Value = "I52" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B207").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I60" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B208").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I61" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B209").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I62" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B210").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I63" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B211").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I71" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B212").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I72" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B213").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I73" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B1214").Value)
    End If
     If Purchasing_Group_List_CO.Value = "I74" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B215").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I75" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B216").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I76" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B217").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I77" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B218").Value)
    End If
     If Purchasing_Group_List_CO.Value = "I78" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B219").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I79" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B220").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I80" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B221").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I81" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B222").Value)
    End If

     If Purchasing_Group_List_CO.Value = "I82" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B223").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I83" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B224").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I84" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B225").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I85" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B226").Value)
    End If

         If Purchasing_Group_List_CO.Value = "I86" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B227").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I87" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B228").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I88" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B229").Value)
    End If

    If Purchasing_Group_List_CO.Value = "I99" Then
        PIC_Name.Value = (ThisWorkbook.Sheets("Purchasing Group Database").Range("B230").Value)
    End If




End Sub

所有这些“ I10,I20,I21 ....”都是单元格的值(A195:1230)。

有没有办法缩短我的电话?我希望它很简单,因为将会有另一个基于数千种不同ID的UserForm。

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作:

width
相关问题