Excel如何从单列搜索结果中获取整行数据

问题描述

如果标题含糊,对不起,我有一个单一的textbox1,您可以在其中键入要查找的内容的一部分,它将显示包含所填写内容的所有匹配项。但是现在,当您找到要查找的内容时然后选择它,我想自动将所有数据从选定结果的行中拉出到正确的文本框。

我有10列,每列的顺序为:ID,序列号,消息,编号,区域,日期,状态,功能,名称,描述。 (它们与图片不符,我翻译了一下) 我正在尝试为某些机器的问题创建数据库,但是我被困住了,完全不知道如何执行此操作。

更糟: 这个搜索功能是一种新形式,它包含了文本的主要形式是所有数据被称为MyUserForm ,看起来会改变,而search form被称为UserForm1,当数据被选中我想要将其拉到另一种形式的文本框中。

Private Sub ListBox1_Click()

Me.TextBox1.Value = ListBox1.Value
ListBox1.Visible = False

End Sub

Function search_text(textTosearch As String)
Dim i As Long
Dim x As Boolean
Dim xvalue As String

Me.ListBox1.Clear
Me.ListBox1.Height = 54

For i = 2 To 501
    xvalue = Cells(i,3).Value
    
    If LCase(xvalue) Like LCase(textTosearch) & "*" = True Then
        If x = False Then
            Me.ListBox1.Visible = True
            x = True
        End If
    
        If xvalue <> "" Then
           Me.ListBox1.AddItem xvalue
        End If
        
        If Me.ListBox1.Height < 260 Then
            Me.ListBox1.Height = Me.ListBox1.Height + 10
        End If
        
    End If
Next

If Me.ListBox1.ListCount <= 0 Then
    Me.ListBox1.Visible = False
End If

End Function

Private Sub TextBox1_Change()
    search_text Me.TextBox1.Value
End Sub

Private Sub UserForm_Initialize()
Me.ListBox1.Visible = False
End Sub


更新 我这样做了,这似乎行得通,如果你们还有提示,是的!

Private Sub CommandButton1_Click()
Unload Me
MyUserForm.show
End Sub

Private Sub ListBox1_Click()

Me.TextBox1.Value = ListBox1.Value
ListBox1.Visible = False

End Sub

Function search_text(textTosearch As String)
Dim i As Long
Dim x As Boolean
Dim xvalue As String

Me.ListBox1.Clear
Me.ListBox1.Height = 54

For i = 2 To 501
    xvalue = Cells(i,3).Value
    
    If LCase(xvalue) Like LCase(textTosearch) & "*" = True Then
        If x = False Then
            Me.ListBox1.Visible = True
            x = True
        End If
    
        If xvalue <> "" Then
           Me.ListBox1.AddItem xvalue
        End If
        
        If Me.ListBox1.Height < 260 Then
            Me.ListBox1.Height = Me.ListBox1.Height + 10
        End If
        
    End If
    If Cells(i,3).Value = TextBox1.Text Then
        MyUserForm.txtDriveNo = Sheet1.Cells(i,2).Value
        MyUserForm.txtMessage = Sheet1.Cells(i,3).Value
        MyUserForm.txtNumber = Sheet1.Cells(i,4).Value
        MyUserForm.cbArea = Sheet1.Cells(i,5).Value
        MyUserForm.txtDatum = Sheet1.Cells(i,6).Value
        MyUserForm.cbStatus = Sheet1.Cells(i,7).Value
        MyUserForm.cbFunctie = Sheet1.Cells(i,8).Value
        MyUserForm.txtNaam = Sheet1.Cells(i,9).Value
        MyUserForm.txtBeschrijving = Sheet1.Cells(i,10).Value
    End If

Next

If Me.ListBox1.ListCount <= 0 Then
    Me.ListBox1.Visible = False
End If

End Function

Private Sub TextBox1_Change()
    search_text Me.TextBox1.Value
End Sub

Private Sub UserForm_Initialize()
Me.ListBox1.Visible = False
End Sub

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)