BUSCAR NOTAS
'Cerrar formulario
Private Sub CommandButton2_Click()
Unload Me
End Sub
'
'Abrir el formulario para modificar
Private Sub CommandButton3_Click()
If Me.ListBox1.ListIndex < 0 Then
MsgBox "No se ha elegido ningún registro", vbExclamation, "EXCELeINFO"
Else
Modificar.Show
End If
End Sub
'
'Eliminar el registro
Private Sub CommandButton4_Click()
Pregunta = MsgBox("Está seguro de eliminar el registro?", vbYesNo + vbQuestion,
"EXCELeINFO")
If Pregunta <> vbNo Then
ActiveCell.EntireRow.Delete
' Fila = Me.ListBox1.ListIndex + 2
' Rows(Fila).Delete
' Application.ScreenUpdating = True
End If
End Sub
Private Sub CommandButton5_Click()
On Error GoTo Errores
If Me.txtFiltro1.Value = "" Then Exit Sub
Me.ListBox1.Clear
j=1
For i = 1 To 18
If Cells(i, j).Offset(0, 2).Value = CInt(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)
Else
End If
Next i
Exit Sub
Errores:
MsgBox "No se encuentra.", vbExclamation, "EXCELeINFO"
End Sub
'
'Activar la celda del registro elegido
Private Sub ListBox1_Click()
Range("a2").Activate
Cuenta = Me.ListBox1.ListCount
For i = 0 To Cuenta - 1
If Me.ListBox1.Selected(i) Then
'MsgBox Me.ListBox1.List(i)
Valor = Me.ListBox1.List(i)
Sheets("Hoja1").Range("A2:A18").Find(What:=Valor, LookAt:=xlWhole,
After:=ActiveCell).Activate
End If
Next i
'Fila = Me.ListBox1.ListIndex + 2
'For i = 1 To 4
' Cells(Fila, 1).Activate
'Next i
End Sub
'Dar formato al ListBox y traer datos de la tabla
Private Sub UserForm_Initialize()
For i = 1 To 4
Me.Controls("Label" & i) = Cells(1, i).Value
Next i
With ListBox1
.ColumnCount = 4
.ColumnWidths = "60 pt;60 pt;60 pt;60 pt"
'.ColumnHeads = True
End With
''ListBox1.RowSource = "Tabla1"
End Sub
MODIFICAR
'Actualizar el registro
Private Sub CommandButton1_Click()
For i = 1 To 4
ActiveCell.Offset(0, i - 1).Value = Me.Controls("TextBox" & i).Value
Next i
Unload Me
End Sub
'
'Cerrar formulario
Private Sub CommandButton2_Click()
Unload Me
End Sub
'
'Llenar los cuadro de texto con los datos del registro elegido
Private Sub UserForm_Initialize()
For i = 1 To 4
Me.Controls("TextBox" & i).Value = ActiveCell.Offset(0, i - 1).Value
Next i
End Sub
OTRO EJEMPLO
'Mostrar resultado en ListBox
Private Sub CommandButton5_Click()
On Error GoTo Errores
If Me.txtFiltro1.Value = "" Then Exit Sub
Me.ListBox1.Clear
Columna = Me.cmbEncabezado.ListIndex
j=1
Filas = Range("a1").CurrentRegion.Rows.Count
For i = 2 To Filas
If LCase(Cells(i, j).Offset(0, CInt(Columna)).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)
Else
End If
Next i
Exit Sub
Errores:
MsgBox "No se encuentra.", vbExclamation, "EXCELeINFO"
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 los encabezados de la tabla
Private Sub UserForm_Initialize()
'
For i = 1 To 4
Me.Controls("Label" & i) = Cells(1, i).Value
Next i
'
With Me
.ListBox1.ColumnCount = 4
.ListBox1.ColumnWidths = "60 pt;60 pt;60 pt;60 pt"
.cmbEncabezado.List = Application.Transpose(ActiveCell.CurrentRegion.Resize(1).Value)
.cmbEncabezado.ListStyle = fmListStyleOption
End With
End Sub