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

问题描述 投票:0回答:1

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

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

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

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

当我按Enter键时,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

Enter的输入按钮:

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
excel vba textbox
1个回答
0
投票

要跳过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
© www.soinside.com 2019 - 2024. All rights reserved.