如何在清除其他用户窗体控件时不清除特定的文本框?

How to not clean a specific Textbox when other Userform controls are cleaned?

在我的用户表单上,我有一个文本框(假设是 Txt1)。我用它作为我的列表框 (Lst1) 的搜索栏。

当我向 Txt1 写入任何表达式时,我会在 Lst1 中找到我要查找的内容。 这两个(Txt1和Lst1)都集成到我的股票程序中了。

当我用Txt1搜索任何产品时,我可以从Lst1中选择产品名称。

当我从Lst1中选择产品时,我将数量写入Txt2并按回车。 它在程序的背面进行了必要的处理。

当我按下回车键时,Txt1 会自行清理。
我需要重新写新的产品名称到Txt1.

我要:
不清理 Txt1.

Txt1 代码:

Private Sub TextBox17_Change()

Dim i As Long
Me.TextBox17.Text = StrConv(Me.TextBox17.Text, 1)
Me.ListBox4.Clear
For i = 2 To Application.WorksheetFunction.CountA(Sayfa2.Range("C:C"))
    a = Len(Me.TextBox17.Text)
    If Left(Sayfa2.Cells(i, 3).Value, a) = Left(Me.TextBox17.Text, a) Then
        Me.ListBox4.AddItem Sayfa2.Cells(i, 3).Value
        Me.ListBox4.List(ListBox4.ListCount - 1, 3) = Sayfa2.Cells(i, 10).Value
    End If
Next i

End Sub

Lst1 代码:

Private Sub ListBox4_Click()

Dim i As Long, lastrow As Long
lastrow = Sheets("CDepo").Range("C" & Rows.Count).End(xlUp).Row
For i = 2 To lastrow
    If CStr(Sheets("CDepo").Cells(i, "C").Value) = (Me.ListBox4.Value) Then
        Me.TextBox2 = Sheets("CDepo").Cells(i, "A").Value
        Me.TextBox11 = Sheets("CDepo").Cells(i, "H").Value
        Me.TextBox9 = Sheets("CDepo").Cells(i, "C").Value
        Me.ComboBox2 = Sheets("CDepo").Cells(i, "B").Value
        Me.TextBox6 = Sheets("CDepo").Cells(i, "I").Value
        Me.TextBox13 = Sheets("CDepo").Cells(i, "J").Value
        Me.TextBox15 = Sheets("CDepo").Cells(i, "P").Value
        Me.TextBox8 = Sheets("CDepo").Cells(i, "D").Value
        Me.TextBox16 = Sheets("CDepo").Cells(i, "Q").Value
    End If
Next

End Sub

用于输入的命令按钮:

Private Sub CommandButton6_Click()

If UserForm11.ComboBox4 = "TesellumFisi" Then

    If TextBox2.Text <> "" Then
        Son_Dolu_Satir = Sheets("TesellumFisi").Range("A65536").End(xlUp).Row

        For i = 23 To Son_Dolu_Satir
            If Sheets("TesellumFisi").Cells(i, 2).Value = TextBox2.Text Then
                Exit Sub
            End If
        Next i
        Bos_Satir = Son_Dolu_Satir + 1
        Sheets("TesellumFisi").Range("A" & Bos_Satir).Value = Application.WorksheetFunction.Max(Sheets("TesellumFisi").Range("A:A")) + 1
        Sheets("TesellumFisi").Range("B" & Bos_Satir).Value = TextBox2.Text
        Sheets("TesellumFisi").Range("C" & Bos_Satir).Value = TextBox13.Text
        Sheets("TesellumFisi").Range("E" & Bos_Satir).Value = TextBox9.Text
        Sheets("TesellumFisi").Range("I" & Bos_Satir).Value = TextBox4.Text
        Sheets("TesellumFisi").Range("J" & Bos_Satir).Value = TextBox6.Text
        Sheets("TesellumFisi").Range("O13").Value = UserForm11.ComboBox1.Text
        Sheets("TesellumFisi").Range("H" & Bos_Satir).Value = UserForm11.ComboBox2.Text
        Sheets("TesellumFisi").Range("G" & Bos_Satir).Value = TextBox8.Text
    End If
End If

Dim TC As Control
For Each TC In Controls
    If TypeName(TC) = "TextBox" Or TypeName(TC) = "ComboBox" Then
        TC.Value = ""
    End If
Next TC
Set TC = Nothing

'--
TextBox2.SetFocus
TextBox2.SelStart = 1
TextBox2.SelLength = Len(TextBox2.Text)

End Sub

要跳过 Text1 但清除其余文本框,您需要在控件循环中添加条件。

Dim TC As Control
    For Each TC In Controls
        If TypeName(TC) = "TextBox" Or TypeName(TC) = "ComboBox" Then
            If Not TC.name = "TextBox1" then 'Assuming this is the right name
                TC.Value = ""
            end if
        End If
    Next TC
    Set TC = Nothing