VBA – USERFORM – find相等的值,并为每个匹配在行中input相邻的值到文本框

我需要升级这个代码find.next版本。 在附件是更好的理解的样本forms。 Keycombobox值可以多次find,相邻值的每个匹配必须位于相邻的文本框中。

数据SEMPLE Keytextbox值= TEST1

.Cells(row with FIRST find TEST1, 1) = textbox10 (located in multipage.page(find)) .Cells(row with SECOND find TEST1, 1) = textbox110 (locateted in multipage.page(alternative find)) 

在这里输入图像说明

 Option Explicit Sub TestFind() Dim sonsat As Long Dim FindRng As Range With Sheets("DATA") Set FindRng = .Range("A:A").Find(Keycombobox.Text) ' <-- assuming Keycombobox is a textBox If Not FindRng Is Nothing Then ' <-- successful find sonsat = FindRng.Row ' rest of yout code here .... .Cells(sonsat, 1) = TextBox10 '<-- for good coding practice use TextBox1.Value ' or TextBox1.Text .Cells(sonsat, 2) = TextBox20 .Cells(sonsat, 3) = TextBox30 .Cells(sonsat, 4) = TextBox40 .Cells(sonsat, 5) = TextBox50 .Cells(sonsat, 6) = TextBox60 .Cells(sonsat, 7) = TextBox70 Else MsgBox "Unable to find " & Keycombobox.Text & " in specified Range !" End If End With End Sub 

可能是你之后:

 Sub TestFind() Dim f As Range Dim firstAddress As String Dim iPage As Long, i As Long With Sheets("DATA").Range("A:A").SpecialCells(xlCellTypeConstants) Set f = .Find(what:=Keycombobox.Text, LookIn:=xlvalkue, lookat:=xlWhole) ' <-- assuming Keycombobox is a textBox If Not f Is Nothing Then firstAddress = f.address Do For i = 1 To 7 Me.Controls("TextBox" & iPage + i * 10) = .Cells(f.Row, i) Next iPage = iPage + 100 Set f = .FindNext(f) Loop While f.address <> firstAddress End If End With End Sub