Está en la página 1de 3

Dim i, items, xEmpleado

'Cambia el TextBox con cada cambio en el Combo


'
Private Sub cmbEncabezado_Change()
Sheets("Li_const").Select
Me.lblFiltro = "Filtro por " & Me.cmbEncabezado.Value
Sheets("Hoja2").Select
End Sub
'
'Cerrar formulario
Private Sub CommandButton2_Click()
Unload Me
Sheets("Hoja2").Select
End Sub
Private Sub CommandButton3_Click()
Sheets("Li_const").Select
If Me.ListBox1.ListIndex < 0 Then
MsgBox "No se ha elegido ningún registro", vbExclamation, "EXCELeINFO"
Else
frmModificar.Show
End If
'Sheets("Hoja2").Select

End Sub

'
'
'Mostrar resultado en ListBox
Private Sub CommandButton5_Click()
On Error GoTo Errores
Sheets("Li_const").Select
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)
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)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 7) = Cells(i, j).Offset(0, 7)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 8) = Cells(i, j).Offset(0, 8)
Sheets("Hoja2").Select
Else
End If
Next i
Exit Sub
Sheets("Hoja2").Select
Errores:
MsgBox "No se encuentra.", vbExclamation, "EXCELeINFO"
End Sub

'
'Activar la celda del registro elegido
Private Sub ListBox1_Click()
'Sheets("Li_const").Select
Range("a2").Activate
Cuenta = Me.ListBox1.ListCount
Set Rango = Range("A1").CurrentRegion
For i = 0 To Cuenta - 4
If Me.ListBox1.Selected(i) Then
Valor = Me.ListBox1.List(i)
Rango.Find(What:=Valor, lookat:=xlWhole, After:=ActiveCell).Activate
End If
Sheets("Hoja2").Select
Next i
Sheets("Hoja2").Select
End Sub
'
'Dar formato al ListBox y traer los encabezados de la tabla
Private Sub UserForm_Initialize()
Sheets("Li_const").Select
For i = 1 To 8
Me.Controls("Label" & i) = Cells(1, i).Value
Next i
'
With Me
.ListBox1.ColumnCount = 8
.ListBox1.ColumnWidths = "20 pt;150 pt;80 pt;80 pt;140 pt;140 pt;50 pt;160 pt"
.cmbEncabezado.List = Application.Transpose(ActiveCell.CurrentRegion.Resize(1).Value)
.cmbEncabezado.ListStyle = fmListStyleOption
Sheets("Hoja2").Select
End With
Sheets("Hoja2").Select
End Sub

Dim Continuar As String


Dim TransRowRng As Range
Dim NewRow As Integer
Dim Limpiar As String
'
strTitulo = "EXCELeINFO"
'
Continuar = MsgBox("Desea agregar los datos?", vbYesNo + vbExclamation, strTitulo)
If Continuar = vbNo Then Exit Sub
'
Cuenta = Application.WorksheetFunction.CountIf(Range("A:A"), Me.TxtID)
'
If Cuenta > 0 Then
'
MsgBox "El DNI '" & Me.TxtID & "' ya se encuentra registrado", vbExclamation, strTitulo
'
Else
'
Set TransRowRng = ThisWorkbook.Worksheets("Li_const").Cells(1, 1).CurrentRegion
NewRow = TransRowRng.Rows.Count + 1
With ThisWorkbook.Worksheets("Li_const")
.Cells(NewRow, 1).Value = Me.TxtID
.Cells(NewRow, 2).Value = Me.TxtUsuario
.Cells(NewRow, 3).Value = Me.TxtFecha
.Cells(NewRow, 4).Value = Me.TxtExpediente
.Cells(NewRow, 5).Value = Me.TxtDireccion
.Cells(NewRow, 6).Value = Me.TxtDescripcion
.Cells(NewRow, 7).Value = Me.TxtAreaLong
.Cells(NewRow, 8).Value = Me.TxtEstado

End With
'
MsgBox "Agregado.", vbInformation, strTitulo
'
Unload Me
End If
'
End Sub

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