Help to export this data

1

Hello, I wish you a good day, the thing is this ...

I currently have this code for a button

Private Sub btnfiltrar_Click()
On Error GoTo ErroresIf 
Me.txtfiltro.Value = "" Or Me.txtfiltro.Value = " " Then
Me.ltbdatos.Clear
Else
Me.ltbdatos.Clear
j = 1
Set BD = ThisWorkbook.Sheets("APU")
Filas = BD.Range("C2").CurrentRegion.Rows.Count
For i = 2 To Filas
    If LCase(BD.Cells(i, j).Offset(0, 2).Value) Like "*" & LCase(Me.txtfiltro.Value) & "*" Then
        Me.ltbdatos.AddItem BD.Cells(i, j)
        Me.ltbdatos.List(Me.ltbdatos.ListCount - 1, 1) = BD.Cells(i, j).Offset(0, 2)
        Me.ltbdatos.List(Me.ltbdatos.ListCount - 1, 2) = BD.Cells(i, j).Offset(0, 15)
    Else
    End If
Next i
End If
Exit Sub
Errores:
MsgBox "No existe.", vbExclamation
End Sub

With this code I bring the data from column A, C and P to a ListBox; But I just need you to bring me the data from columns C and P, how should I modify that code to achieve what I want?

    
asked by Juan Arango 22.02.2018 в 15:17
source

1 answer

0

the line that takes the value of column A is Me.ltbdatos.AddItem BD.Cells(i, j ). But from what I see, your Listbox has 3 columns

  

(Cod, Name, Total Value).

You should modify your listbox so that it is only two columns, and then modify the code so that it fills both columns so that:

Me.ltbdatos.AddItem  = BD.Cells(i, j).Offset(0, 2)
Me.ltbdatos.List(Me.ltbdatos.ListCount - 1, 1) = BD.Cells(i, j).Offset(0, 15)

Another option, although I do not guarantee that it will work, and I also see it as less professional and dirty , but it can help you get through, it would be to try to trick the Listbox and fill in the Cod column with blank values. Something like:

Me.ltbdatos.AddItem " "
Me.ltbdatos.List(Me.ltbdatos.ListCount - 1, 1) = BD.Cells(i, j).Offset(0, 2)
Me.ltbdatos.List(Me.ltbdatos.ListCount - 1, 2) = BD.Cells(i, j).Offset(0, 15)

But my professional recommendation is that you do the first thing I said . As your Listbox is designed, why would you not want to show the value of column A? I do not finish seeing the utility to remove it. Does it bother you in any way?

    
answered by 22.02.2018 / 17:47
source