lunes, 29 de mayo de 2023

EXCEL USERFORM ACTUALIZA

BOTON BUSCAR

Private Sub CommandButton1_Click()
    frmBuscar.Show
End Sub

ABRE USERFORM MODIFICAR
'Abrir el formulario para modificar
Private Sub CommandButton3_Click()
If Me.ListBox1.ListIndex < 0 Then
    MsgBox "No se ha elegido ningún registro", vbExclamation, "MODIFICACION"
Else
    frmModificar.Show
End If
End Sub


'Mostrar resultado en ListBox
Private Sub CommandButton5_Click()
On Error GoTo Errores
If Me.txtFiltro1.Value = "" Then Exit Sub
Me.ListBox1.Clear
' (1) que busca en la columna 2
j = 1
Filas = Range("A1").CurrentRegion.Rows.Count
' (1)busca en la columna 2
For i = 1 To Filas
    If LCase(Cells(i, j).Offset(0, 1).Value) Like "*" & LCase(Me.txtFiltro1.Value) & "*" Then
        Me.ListBox1.AddItem Cells(i, j)
        Me.ListBox1.list(Me.ListBox1.ListCount - 1, 1) = Cells(i, j).Offset(0, 1)
        Me.ListBox1.list(Me.ListBox1.ListCount - 1, 2) = Cells(i, j).Offset(0, 2)
        Me.ListBox1.list(Me.ListBox1.ListCount - 1, 3) = Cells(i, j).Offset(0, 3)
        Me.ListBox1.list(Me.ListBox1.ListCount - 1, 4) = Cells(i, j).Offset(0, 4)
        Me.ListBox1.list(Me.ListBox1.ListCount - 1, 5) = Cells(i, j).Offset(0, 5)
        Me.ListBox1.list(Me.ListBox1.ListCount - 1, 6) = Cells(i, j).Offset(0, 6)
    Else
    End If
Next i
Exit Sub
Errores:
MsgBox "No se encuentra.", vbExclamation, "REGISTRO DE CALIFICACIONES"
End Sub


'Activar la celda del registro elegido
Private Sub ListBox1_Click()
Range("A2").Activate
Cuenta = Me.ListBox1.ListCount
Set Rango = Range("A1").CurrentRegion
For i = 0 To Cuenta - 1
    If Me.ListBox1.Selected(i) Then
        Valor = Me.ListBox1.list(i)
        Rango.Find(What:=Valor, LookAt:=xlWhole, After:=ActiveCell).Activate
    End If
Next i
End Sub


'Dar formato al ListBox y traer datos de la tabla
Private Sub UserForm_initialize()
For i = 1 To 7
    Me.Controls("Label" & i) = Cells(1, i).Value
Next i

With ListBox1
    .ColumnCount = 7
    .ColumnWidths = "20 pt;160 pt;30 pt;30 pt;30 pt;30 pt;30 pt"
End With
End Sub


'Cerrar formulario
Private Sub CommandButton2_Click()
Unload Me
End Sub




'Actualizar el registro
Private Sub CommandButton1_Click()
For i = 3 To 7
   ActiveCell.Offset(0, i - 1).Value = Me.Controls("TextBox" & i).Value
Next i
Unload Me
End Sub

'Llenar los cuadro de texto con los datos del registro elegido
Private Sub UserForm_initialize()
For i = 1 To 7
    Me.Controls("TextBox" & i).Value = ActiveCell.Offset(0, i - 1).Value
Next i
End Sub

'Cerrar formulario
Private Sub CommandButton2_Click()
Unload Me
End Sub

No hay comentarios:

Publicar un comentario