REestructurar un codigo de busqueda y filtro...
Tengo un formulario que contiene un listbox que debería cargarse, ahí esta bien, entonces según cuando pongo dato en un textbox1 este me debe filtrar, lo cual esta bien, lo que no esta bien es que cuando borro el dato de textbox1 este me debería mostrar todos los datos de nuevo y NO LO HACE, para eso tengo este código:
Private Sub TextBox1_Change()
On Error Resume Next
Set b = Sheets("HOJA DE SUELDOS")
uf = b.Range("A" & Rows.Count).End(xlUp).Row
If Trim(TextBox1.Value) = "" Then
'Me.ListBox1.List() = b.Range("A2:H" & uf).Value
TextBox3.Value = ""
Me.ListBox1.RowSource = "HOJA DE SUELDOS!A2:U" & uf
Exit Sub
End If
b.AutoFilterMode = False
Me.ListBox1 = Clear
Me.ListBox1.RowSource = Clear
For I = 2 To uf
strg = b.Cells(I, 2).Value
If UCase(strg) Like UCase(TextBox1.Value) & "*" Then
Me.ListBox1.AddItem b.Cells(I, 1)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = b.Cells(I, 2)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = b.Cells(I, 3)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = b.Cells(I, 4)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = b.Cells(I, 5)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = b.Cells(I, 6)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = b.Cells(I, 7)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 7) = b.Cells(I, 8)
End If
Next I
Me.ListBox1.ColumnWidths = "20 pt;150 pt;130 pt;40 pt;90 pt;30 pt"
End Sub
cuando inicia el formulario esta bien
Private Sub UserForm_Initialize()
Dim fila As Long
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set b = Sheets("HOJA DE SUELDOS")
uf = b.Range("A" & Rows.Count).End(xlUp).Row
uc = b.Cells(1, Columns.Count).End(xlToLeft).Address
wc = Mid(uc, InStr(uc, "$") + 1, InStr(2, uc, "$") - 2)
With Me.ListBox1
.ColumnCount = 6
.ColumnWidths = "20 pt;150 pt;130 pt;40 pt;90 pt;30 pt"
.RowSource = "A2:" & wc & uf
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = Trueend sub
El RANGO de HOJA SUELDO es de A:U ahí están los datos, el otro problema que cuando busco un dato dentro de la lista este me busca el dato pero resulta que se encuentra fuera de el rango que antes mencione
Private Sub TextBox3_Change()
On Error Resume Next
Dim var2 As Variantvar2 = TextBox3
Cells.Find(What:=TextBox3.Value, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If var2 = ActiveCell.Value Then
TextBox4.Value = ActiveCell.Offset(0, 1) 'depto
ejemplos:

me busca el dato pero se encuentra en AB y (cosa que se sale del rango)

Me debería poner B106 Y no el AB104, ¿por qué me sucede esto? Ayudenme por favor! ¿Qué hago mal?