Estoy haciendo una busqueda con macro en base a 2 criterios por dni o por apellido utilizando el siguiente codigo:
Private Sub btn_buscardata_Click()
Dim contador As Integer
Dim s As String
Dim i As Integer
s = txt_criterio.Text
contador = 2
Dim flg As Boolean
If rb_dni.Value Then
contador = 1
End If
If rb_apellidos.Value Then
contador = 4
End If
lbx_datos.ListIndex = -1
If txt_criterio.Text = "" Then
Exit Sub
End If
For i = 0 To lbx_datos.ListCount - 1
If UCase(lbx_datos.List(i, contador)) Like UCase(s & "*") Then
lbx_datos.ListIndex = i
flg = True
Exit For
Exit Sub
End If
Next
If Not flg Then MsgBox "No se encuentra registrado"
End Sub
La ejecucion de la macro es muy lenta ya que tengo 2000 datos en donde hace la busqueda y cuando busca alguien cuyo apellido empieza con Z por ejemplo demora demasiado.
Espero puedan ayudarme.
Gracias.
Featured Replies
Archivado
Este tema está ahora archivado y está cerrado a más respuestas.
Estoy haciendo una busqueda con macro en base a 2 criterios por dni o por apellido utilizando el siguiente codigo:
Private Sub btn_buscardata_Click()
Dim contador As Integer
Dim s As String
Dim i As Integer
s = txt_criterio.Text
contador = 2
Dim flg As Boolean
If rb_dni.Value Then
contador = 1
End If
If rb_apellidos.Value Then
contador = 4
End If
lbx_datos.ListIndex = -1
If txt_criterio.Text = "" Then
Exit Sub
End If
For i = 0 To lbx_datos.ListCount - 1
If UCase(lbx_datos.List(i, contador)) Like UCase(s & "*") Then
lbx_datos.ListIndex = i
flg = True
Exit For
Exit Sub
End If
Next
If Not flg Then MsgBox "No se encuentra registrado"
End Sub
La ejecucion de la macro es muy lenta ya que tengo 2000 datos en donde hace la busqueda y cuando busca alguien cuyo apellido empieza con Z por ejemplo demora demasiado.
Espero puedan ayudarme.
Gracias.