Mostrar datos de una sola columna de una hoja en un listbox de excel
Me pueden aclarar un poco más de acurdo a un proyecto que tengo y quisiera sacar los datos de una sola columna de cierta hoja en este caso particular sera "HOJA2" que me muestre los datos solo de la columna "B" y no toda la fila como lo tengo en el proyecto
Option Explicit
Dim a As Variant
Sub FilterData()
Dim txt1 As String
Dim i As Long, j As Long, k As Long
'
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
ListBox2.Clear
For i = 1 To UBound(a, 1) 'linea que mellega al ultimo registro
If txtbuscaproR.Value = "" Then txt1 = a(i, 1) Else txt1 = txtbuscaproR.Value
If LCase(a(i, 2)) Like "*" & LCase(txt1) & "*" Then 'linea que me lleva a la columna requerida
j = j + 1
For k = 1 To UBound(a, 2)
b(j, k) = a(i, k)
If k = 4 Or k = 5 Then
b(j, k) = Format(b(j, k), "$ #,##0.00")
End If
Next
End If
Next i
If j > 0 Then ListBox2.List = b
End Sub
Private Sub UserForm_Activate()
a = Sheets(Hoja3.Name).Range("A2:B" & Sheets(Hoja3.Name).Range("A" & Rows.Count).End(3).Row).Value
ListBox2.ColumnCount = UBound(a, 2)
End Sub
Private Sub UserForm_Initialize()
a = Sheets(Hoja3.Name).Range("A2:B" & Sheets(Hoja3.Name).Range("A" & Rows.Count).End(3).Row).Value
' ListBox2.ColumnCount = UBound(a, 2)
'a = Sheets(Hoja2.Name).Range("A2").Row.Count
'
With ListBox2
.List = a
.ColumnCount = Worksheets(Hoja3.Name).Range("A2").CurrentRegion.Row.Count
'
End With
End Sub
1 respuesta
Respuesta de Dante Amor
1