Excel - Pasar datos de hoja a listbox

 
Vista:
Imágen de perfil de Francis

Pasar datos de hoja a listbox

Publicado por Francis (1 intervención) el 18/06/2017 23:39:34
Soy muy nuevo en esto
Lo necesito para el proyecto final de ciclo :( :(

He averiguado mucho pero no soluciono el problema

Primeramente un saludo a todos ..

Tengo una "hojaX" con 10 columnas y
dependiendo de los datos que se vayan ingresando se tiene un numero X de filas.
(No esta en tabla)

QUIERO PASAR LOS DATOS DE "hojaX" A UN "ListBox" MEDIANTE UN BOTÓN

TENGO EL SIGUIENTE CÓDIGO EN EL USEFORM:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Private Sub cmdsearcharticle_Click()
 
Dim nombreHoja As String
Dim numhoja As String
Dim numhoja1 As String
 
Application.ScreenUpdating = False
 
    nombreHoja = txtcheck.Value
 
    If (BuscarHoja2(nombreHoja)) Then
 
        numhoja = Worksheets(nombreHoja).Index
        numhoja1 = "Hoja" & (numhoja - 1)
 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' ESTE EL PROBLEMA
 
    Sheets(nombreHoja).Select
    Range("A3").Select
    While ActiveCell.Value <> ""
    Me.ListBox1.AddItem ActiveCell
    ActiveCell.Offset(1, 0).Select
    Wend
    Hoja9.Select
 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Else
        MsgBox nombreHoja & " no existe"
    End If
 
Application.ScreenUpdating = True
 
End Sub

Y EL SIGUIENTE CÓDIGO EN EL MODULO:

1
2
3
4
5
6
7
8
Sub RevisarDia()
FrmRevisarDia.Show
End Sub
 
Function BuscarHoja2(nombreHoja As String) As Boolean
    On Error Resume Next
    BuscarHoja2 = (Worksheets(nombreHoja).Name <> "")
End Function


MI PROBLEMA ES QUE:

Al momento de pulsar el botón solo me aparecen los datos de la primera columna

LA SOLUCIÓN CON SU AYUDA SERIA:

Poder visualizar todos los valores de la hoja en el listbox...
Sin tabla por favor ya que esto me genera otro problema :( :(

En el archivo adjunto:

En la hoja llamada "buscar" esta el boton, donde dice "Ingresar Busqueda" se pone el nombre Hoja1.

Infinitas gracias...
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Pasar datos de hoja a listbox

Publicado por Cacho R (1 intervención) el 21/06/2017 09:26:48
Hola! Francis.
Sustituye lo que tienes por esto otro:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Private Sub cmdsearcharticle_Click()
Dim ws As Worksheet
 
On Error Resume Next
  Set ws = Sheets(CStr(txtcheck))
  If ws Is Nothing <> 0 Then
    MsgBox "<" & txtcheck & "> no existe."
    Exit Sub
  End If
On Error GoTo 0
 
If ws.Range("a3") = "" Then
  ListBox1.Clear
  MsgBox "La hoja no contiene info."
Else
  ListBox1.List = ws.Range("j3", ws.Cells(ws.Rows.Count, "a").End(xlUp)).Value
End If
 
Set ws = Nothing
End Sub
 
Private Sub UserForm_Initialize()
  ListBox1.ColumnCount = 10
  ListBox1.ColumnHeads = False
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar