H o l a:
Esta es la parte que agregué al código:
'Validar si es la columna código para reemplzar R1 por R000001
If col = 1 Then
titulo = Left(titulo, 1) & Format(Mid(titulo, 2), "000000")
End If
completo:
'
Private Sub CommandButton1_Click()
'Por.Dante Amor
'Application.ScreenUpdating = False
'Buscar
Set h1 = Sheets("TITULOS")
Set h2 = Sheets("FILTRO")
h2.Cells.Clear
titulo = UCase(TextBox1)
If titulo = "" Then
'MsgBox "Introduce una palabra para buscar", vbExclamation, "BUSCAR"
'TextBox1.SetFocus
'Application.ScreenUpdating = True
'Exit Sub
FiltrarTodo h1, h2
Exit Sub
End If
'
If IsNumeric(titulo) Then titulo = Val(titulo)
j = 2
col = ComboBox1.ListIndex + 1
'
'Validar si es la columna código para reemplzar R1 por R000001
If col = 1 Then
titulo = Left(titulo, 1) & Format(Mid(titulo, 2), "000000")
End If
ucol = h1.Cells(1, Columns.Count).End(xlToLeft).Column + 1
h1.Columns(ucol).ClearContents
If ComboBox1 = "" Then
Set r = h1.Cells
Else
Set r = h1.Columns(col)
End If
Set b = r.Find(titulo, lookat:=xlPart, LookIn:=xlValues)
If Not b Is Nothing Then
ncell = b.Address
h1.Rows(1).Copy h2.Rows(1)
If ComboBox1 = "" Then
col = b.Column
End If
Do
'detalle
htit = UCase(h1.Cells(b.Row, col))
If htit Like titulo Or _
htit Like "* " & titulo Or _
htit Like titulo & " *" Or _
htit Like "* " & titulo & " *" Then
If h1.Cells(b.Row, ucol) = "" And b.Row > 2 Then
h1.Rows(b.Row).Copy h2.Rows(j) '.PasteSpecial Paste:=xlValues
h2.Cells(j, ucol) = b.Row
j = j + 1
h1.Cells(b.Row, ucol) = "x"
End If
End If
'
'If h1.Cells(b.Row, ucol) = "" And b.Row > 2 Then
' h1.Rows(b.Row).Copy h2.Rows(j) '.PasteSpecial Paste:=xlValues
' h2.Cells(j, ucol) = b.Row
' j = j + 1
' h1.Cells(b.Row, ucol) = "x"
'End If
'
Set b = r.FindNext(b)
Loop While Not b Is Nothing And b.Address <> ncell
u = h2.Range("A" & Rows.Count).End(xlUp).Row
If u = 1 Then
MsgBox "No se encontraron resultados"
Else
h2.Columns(ucol).Cut
h2.Columns("A:A").Insert Shift:=xlToRight
h2.[A1] = "FILA"
h2.Cells.EntireColumn.AutoFit
'
ucol = h2.Cells(1, Columns.Count).End(xlToLeft).Column
letra = Evaluate("=SUBSTITUTE(ADDRESS(1," & ucol & ",4),""1"","""")")
For i = 1 To ucol
cad = cad & Int(h2.Cells(1, i).Width) + 1 & ";"
Next
ComboBox1.SetFocus
ComboBox2.Enabled = False
ListBox1.ColumnCount = ucol
ListBox1.ColumnWidths = cad
'
ListBox1.RowSource = h2.Name & "!A2:" & letra & u
End If
Else
MsgBox "No se encontraron resultados"
End If
Set h1 = Nothing
Set h2 = Nothing
Set b = Nothing
Set r = Nothing
Application.ScreenUpdating = True
End Subs a l u d o s