Error 1004: Error en el método 'Range' de objeto '_Worksheet?
Dim i, items, xEmpleado
Private Sub btn_Buscar_Click()
If Me.txt_Buscar.Value = Empty Then
MsgBox "Escriba un registro para buscar"
Me.ListBox1.Clear
Me.txt_Buscar.SetFocus
Exit Sub
End If
Me.ListBox1.Clear
items = Range("Tabla1").CurrentRegion.Rows.Count
For i = 2 To items
If LCase(Cells(i, 1).Value) Like "*" & LCase(Me.txt_Buscar.Value) & "*" Then
Me.ListBox1.AddItem Cells(i, 1)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = Cells(i, 2)
ElseIf LCase(Cells(i, 2).Value) Like "*" & LCase(Me.txt_Buscar.Value) & "*" Then
Me.ListBox1.AddItem Cells(i, 1)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = Cells(i, 2)
End If
Next i
Me.txt_Buscar.SetFocus
Me.txt_Buscar.SelStart = 0
Me.txt_Buscar.SelLength = Len(Me.txt_Buscar.Text)
Exit Sub
End Sub
Private Sub btn_Eliminar_Click()
Dim Fila As Integer
Dim Final As Integer
If Me.ListBox1.ListIndex = -1 Then
MsgBox "Debe seleccionar un registro"
Exit Sub
End If
'Buscamoos la última fila
Fila = 2
Do While Hoja1.Cells(Fila, 1) <> ""
Fila = Fila + 1
Loop
Final = Fila - 1
If MsgBox("¿Seguro que quiere eliminar este Registro?", vbQuestion + vbYesNo) = vbYes Then
For Fila = 2 To Final
If Hoja1.Cells(Fila, 1) = xEmpleado Then
Hoja1.Cells(Fila, 1).EntireRow.Delete
Exit For
End If
Next
Call btn_Buscar_Click
MsgBox "Registro eliminado", vbInformation + vbOKOnly
Else
Exit Sub
End If
End Sub
Private Sub ListBox1_Click()
'Determino que cuando selecciono un item,
'el valor seleccionado, sea asignado a la variable xEmpleado
items = Me.ListBox1.ListCount
For i = 0 To items - 1
If Me.ListBox1.Selected(i) Then
xEmpleado = Me.ListBox1.List(i)
End If
Next i
Fila = ListBox1.ListIndex + 2
With Hoja1.Range(ListBox1.RowSource)
TextBox1.Text = .Offset(ListBox1.ListIndex, 0).Resize(1, 1).Value
TextBox2.Text = .Offset(ListBox1.ListIndex, 1).Resize(1, 1).Value
TextBox3.Text = .Offset(ListBox1.ListIndex, 2).Resize(1, 1).Value
End With
End Sub
Private Sub UserForm_Initialize()
'Le digo cuántas columnas
ListBox1.ColumnCount = 2
'Asigno el ancho a cada columna
Me.ListBox1.ColumnWidths = "200 pt;50 pt"
'El origen de los datos es la Tabla1
ListBox1.RowSource = "Tabla1"
End Sub