首页 > 解决方案 > 组合框选择发生变化,选定的值将在某个字符之后附加到文本框中

问题描述

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

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

标签: excelvba

解决方案


推荐阅读