组合框选择发生变化,所选值将在某个字符后附加到文本框中

时间:2019-02-18 07:33:56

标签: excel vba

组合框中有某些值,当我更改这些值时,我选择的值应在某个单词后的文本框中填充。 我编写的代码不断添加组合框选择的值,而不是清除并仅填充新选择的值。 请帮忙。

Private Sub cboTrial_Change()
    Dim Searchthis As String
    Dim StartTxt, MidTxt, EndTxt As String
    Dim index As Integer

Dim s As String
StartTxt = VBA.vbNullString
MidTxt = VBA.vbNullString
EndTxt = VBA.vbNullString

Cells(1, 5).Value = cboTrial.Value

If Me. cboTrial.Enabled = VBA.vbTrue Then
    If Me. cboTrial.Value <> VBA.vbNullString Then
        Call FlagControl(cboTrial, VBA.vbFalse)
    End If
    Searchthis = "by"
    index = InStr(1, txt, Searchthis) + 2

       If index > 0 Then
            StartTxt = mid(txt, 1, index)
            MidTxt = Me. cboTrial.Value
            EndTxt = mid(txt, index, Len(txt))
            txt= StartTxt & MidTxt & EndTxt
        End If
End If
End Sub

0 个答案:

没有答案