我有一个带有姓名和年龄的表格以及一个命令按钮,此按钮可打开客户搜索屏幕。当我搜索 Andrew 的名字时,我得到了 3 个结果,我转到第 3 页(共 3 页)并执行新的搜索,所以箭头不起作用,您知道错误可能在哪里吗?
Public MatrizResultados As Variant
Public Total_Ocorrencias As Long
Private Sub btn_Procurar_Click()
If Me.txt_Procurar.Text = "" Then
MsgBox "Enter a name"
Else
Call ProcuraPersonalizada(Me.txt_Procurar.Text)
End If
End Sub
Private Sub Label6_Click()
End Sub
Private Sub Label7_Click()
End Sub
Private Sub SpinButton1_Change()
Dim Linha As Long
Dim TotalOcorrencias As Long
TotalOcorrencias = SpinButton1.Max + 1
Linha = MatrizResultados(SpinButton1.Value)
Label_Registros_Contador.Caption = SpinButton1.Value + 1 & " de " & TotalOcorrencias
TextBox1.Text = Plan1.Cells(Linha, 1).Value
TextBox2.Text = Plan1.Cells(Linha, 2).Value
End Sub
Private Sub ProcuraPersonalizada(ByVal TermoPesquisado As String)
Dim Busca As Range
Dim Primeira_Ocorrencia As String
Dim Resultados As String
'perform the search
Set Busca = Plan1.Cells.Find(What:=TermoPesquisado, After:=Range("A1"), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not Busca Is Nothing Then
Primeira_Ocorrencia = Busca.Address
Resultados = Busca.Row
Do
Set Busca = Plan1.Cells.FindNext(After:=Busca)
If Not Busca.Address Like Primeira_Ocorrencia Then
Resultados = Resultados & ";" & Busca.Row
End If
Loop Until Busca.Address Like Primeira_Ocorrencia
MatrizResultados = Split(Resultados, ";")
SpinButton1.Max = UBound(MatrizResultados)
SpinButton1.Enabled = True
Label_Registros_Contador.Caption = "1 de " & UBound(MatrizResultados) + 1
TextBox1.Text = Plan1.Cells(MatrizResultados(0), 1).Value
TextBox2.Text = Plan1.Cells(MatrizResultados(0), 2).Value
Else
SpinButton1.Enabled = False
Label_Registros_Contador.Caption = ""
TextBox1.Text = ""
TextBox2.Text = ""
MsgBox "No results for '" & TermoPesquisado & "' was found."
End If
txt_Procurar.Text = ""
txt_Procurar.SetFocus
End Sub
Private Sub TextBox2_Change()
End Sub
Private Sub UserForm_Initialize()
SpinButton1.Enabled = False
Label_Registros_Contador.Caption = ""
End Sub
你只需要重置 Spin 按钮,它认为它仍然在第 3 个条目上(你可以通过选项反转,然后当你再次尝试前进时它会是正确的)。
添加这一行:
SpinButton1.Value = 0
在你开始弄乱它之前的某个地方,我把它放在了:
MatrizResultados = Split(Resultados, ";")
SpinButton1.Value = 0
SpinButton1.Max = UBound(MatrizResultados)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句