Tengo un problema con un filtro en vba

Tengo un problema y quiero ver si me pueden ayudar, resulta que hice un formulario, todo bien con eso, pero ahora hice un botón para modificar algunos datos, en este botón se encuentra el filtro que sera la letra que buscare en mi base de datos y como respuesta obtendré todas las similitudes a mi filtro, pero tengo un problema, ya que al seleccionar una fila, me salta un error
este es el código
Private Sub ListBox1_Click()
Range("a2").Activate
Cuenta = Me.ListBox1.ListCount
Set rengar = Range("A1").CurrentRegion
For i = 0 To Cuenta - 1
If Me.ListBox1.Selected(i) Then
Valor = Me.ListBox1.List(i)
rengar.Find(What:=Valor, LookAt:=xlWhole, After:=ActiveCell).Activate
End If
Next i
End Sub    

Las columnas que se verán reflejados en este lista, serán
Fecha - usuario - tipo - actividades 1 ... Actividades n

Y el otro problema que tengo es que al darle click a la fila que quiero modificar, no la selecciona, se queda con la primera similitud.

Respuesta
1

H o la: envíame tu archivo con el formulario; y me explicas con un ejemplo, qué quieres hacer, una vez encontrado el registro a modificar.

Mi correo [email protected]

En el asunto del correo escribe tu nombre de usuario “diego flores” y el título de esta pregunta.

Te anexo el código del form buscar

Dim h1
'
Private Sub CommandButton5_Click()
'Mostrar resultado en ListBox
    Me.ListBox1.Clear
    If Me.txtFiltro1.Value = "" Then Exit Sub
    Filas = h1.Range("a1").CurrentRegion.Rows.Count
    For i = 2 To Filas
        If LCase(h1.Cells(i, "B").Value) Like "*" & LCase(Me.txtFiltro1.Value) & "*" Then
            Me.ListBox1.AddItem h1.Cells(i, "A")
            Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = h1.Cells(i, "B")
            Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = h1.Cells(i, "C")
            Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = h1.Cells(i, "D")
            Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = h1.Cells(i, "E")
            Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = h1.Cells(i, "F")
            Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = h1.Cells(i, "G")
            Me.ListBox1.List(Me.ListBox1.ListCount - 1, 7) = h1.Cells(i, "H")
            Me.ListBox1.List(Me.ListBox1.ListCount - 1, 8) = i  'almacena el número de fila
        End If
    Next i
End Sub
'
Private Sub CommandButton3_Click()
'Abrir el formulario para modificar
    If Me.ListBox1.ListIndex < 0 Then
        MsgBox "No se ha elegido ningún registro", vbExclamation, "EXCELeINFO"
    Else
        frmModificar.Show
        Call CommandButton5_Click
    End If
End Sub
'
Private Sub UserForm_Initialize()
'Dar formato al ListBox y traer datos de la tabla
    '
    Set h1 = Sheets("Base")
    '
    For i = 1 To 8
        Me.Controls("lavel" & i) = Cells(1, i).Value
    Next i
    With ListBox1
        .ColumnCount = 8
        .ColumnWidths = "60 pt;60 pt;60 pt;60 pt"
    End With
End Sub

El código del form modificar

Dim h1
'
'Actualizar el registro
Private Sub CommandButton1_Click()
    fila = frmBuscar.ListBox1.List(frmBuscar.ListBox1.ListIndex, 8)
    For i = 1 To 8
        h1.Cells(fila, i).Value = Me.Controls("hola" & i).Value
    Next i
    Unload Me
End Sub
'
'Llenar los cuadro de texto con los datos del registro elegido
Private Sub UserForm_Initialize()
    'obtiene la fila almacenada
    Set h1 = Sheets("Base")
    fila = frmBuscar.ListBox1.List(frmBuscar.ListBox1.ListIndex, 8)
    For i = 1 To 8
        Me.Controls("hola" & i).Value = h1.Cells(fila, i)
    Next i
End Sub
'
'Cerrar formulario
Private Sub CommandButton2_Click()
    Unload Me
End Sub
'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas