EXCEL VBA: Rowsource problem

Anonimo
2016-02-08T10:30:49+00:00

Buongiorno a tutti e grazie in anticipo per l'aiuto.

Ho un problema nel popolare una listbox a partire da una tabella.

Il problema sorge perchè ho la necessità che la listbox venga popolata esclusivamente dalle righe della tabella che risultano visibili avendo prima applicato un filtro sulla tabella. 

Grazie

Microsoft 365 e Office | Excel | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento
Risposta accettata dall'autore della domanda
Anonimo
2016-02-08T10:46:34+00:00

Immaginando (tu non lo specifichi) che la tua tabella inizi da A1 nel Foglio1 e che la tua Listbox sia in una UserForm e che lo voglia fare tramite un CommandButton:

Private Sub CommandButton1_Click()

    Dim sh As Worksheet

    Dim rng As Range

    Dim lCol As Long

    Application.ScreenUpdating = False

    Set sh = ThisWorkbook.Worksheets("Foglio1")

    Set rng = sh.Range("A1").CurrentRegion.SpecialCells(xlCellTypeVisible)

    lCol = rng.Columns.Count

    With Me.ListBox1

        .ColumnCount = lCol

        .Clear

        rng.Copy

        ThisWorkbook.Worksheets.Add

        ActiveSheet.Range("A1").PasteSpecial

        Set rng = ActiveSheet.Range("A1").CurrentRegion

        Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)

        .List = rng.Value

    End With

    With Application

        .DisplayAlerts = False

        ActiveSheet.Delete

        .DisplayAlerts = True

        .ScreenUpdating = True

    End With

    Set rng = Nothing

    Set sh = Nothing

End Sub

La risposta è stata utile?

0 commenti Nessun commento

3 risposte aggiuntive

Ordina per: Più utili
  1. Anonimo
    2016-02-08T11:39:36+00:00

    Bene!

    Ciao.

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2016-02-08T11:20:10+00:00

    Scusami....non avevo letto bene....

    GRAZIEEEE

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2016-02-08T11:18:11+00:00

    Immaginando (tu non lo specifichi) che la tua tabella inizi da A1 nel Foglio1 e che la tua Listbox sia in una UserForm e che lo voglia fare tramite un CommandButton:

    Private Sub CommandButton1_Click()

     

        Dim sh As Worksheet

        Dim rng As Range

        Dim lCol As Long

     

        Application.ScreenUpdating = False

        Set sh = ThisWorkbook.Worksheets("Foglio1")

        Set rng = sh.Range("A1").CurrentRegion.SpecialCells(xlCellTypeVisible)

         

        lCol = rng.Columns.Count

         

        With Me.ListBox1

            .ColumnCount = lCol

            .Clear

            rng.Copy

            ThisWorkbook.Worksheets.Add

            ActiveSheet.Range("A1").PasteSpecial

            Set rng = ActiveSheet.Range("A1").CurrentRegion

            Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)

            .List = rng.Value

        End With

         

        With Application

            .DisplayAlerts = False

            ActiveSheet.Delete

            .DisplayAlerts = True

            .ScreenUpdating = True

        End With

         

        Set rng = Nothing

        Set sh = Nothing

         

    End Sub

    Grazie mille,

    l'unica cosa che non trovo nel listato è proprio l'informazione relativa alla listbox.

    Sbaglio io a vedere?

    La risposta è stata utile?

    0 commenti Nessun commento