XL 2019 Afficher lignes dans LISTBOX

guiyom

XLDnaute Junior
Bonsoir,

J'aurais besoin de vos lumières sur la possibilité ou non de pouvoir afficher uniquement les valeurs de la colonne TOTAL différent de 0 dans la LISTBOX.

La source de la LISTBOX est appelée via :

VB:
Private Sub UserForm_Initialize()

ListBox1.List = Sheets("Feuil1").Range("D11:L36").Value

End Sub

Je joint un fichier d'exemple

Cordialement
 

Pièces jointes

  • tesrt.xlsm
    23.4 KB · Affichages: 23

_Thierry

XLDnaute Barbatruc
Repose en paix
Bonsoir @guiyom , le Forum

Tu devrais faire un essai comme ceci dans ton UserForm6 :

VB:
Option Explicit

Private Sub UserForm_Initialize()
Dim Ws As Worksheet
Dim RngPlage As Range
Dim TabPlage As Variant
Dim i As Integer, x As Integer
Dim c As Byte

Set Ws = ThisWorkbook.Worksheets("Feuil1")
Set RngPlage = Ws.Range("D11:L" & Ws.Range("L1000").End(xlUp).Row)
TabPlage = RngPlage

'ListBox1.List = TabPlage '>>>> SANS FILTRE

For i = 1 To UBound(TabPlage, 1)
    If TabPlage(i, 9) <> 0 Then ' >>>>>>>>>> LE FILTRE !!!
        With Me.ListBox1
        .TextAlign = fmTextAlignRight
            .AddItem TabPlage(i, 1)
                For c = 1 To 8
'                    .Column(c, x) = TabPlage(i, c + 1) ">>>> Without Format
                    .Column(c, x) = Format(TabPlage(i, c + 1), "# ### ### ##0.00")
                Next c
         x = x + 1
         End With
    End If
Next i

End Sub

Bonne soirée
@+Thierry
 

guiyom

XLDnaute Junior
Bonsoir @guiyom , le Forum

Tu devrais faire un essai comme ceci dans ton UserForm6 :

VB:
Option Explicit

Private Sub UserForm_Initialize()
Dim Ws As Worksheet
Dim RngPlage As Range
Dim TabPlage As Variant
Dim i As Integer, x As Integer
Dim c As Byte

Set Ws = ThisWorkbook.Worksheets("Feuil1")
Set RngPlage = Ws.Range("D11:L" & Ws.Range("L1000").End(xlUp).Row)
TabPlage = RngPlage

'ListBox1.List = TabPlage '>>>> SANS FILTRE

For i = 1 To UBound(TabPlage, 1)
    If TabPlage(i, 9) <> 0 Then ' >>>>>>>>>> LE FILTRE !!!
        With Me.ListBox1
        .TextAlign = fmTextAlignRight
            .AddItem TabPlage(i, 1)
                For c = 1 To 8
'                    .Column(c, x) = TabPlage(i, c + 1) ">>>> Without Format
                    .Column(c, x) = Format(TabPlage(i, c + 1), "# ### ### ##0.00")
                Next c
         x = x + 1
         End With
    End If
Next i

End Sub

Bonne soirée
@+Thierry
Bonjour @thierry, le forum

C'est exactement le résultat recherché, merci pour le temps que vous avez accordé à mon probléme.

Pas mal de termes que je ne connais pas, je vais regarder ça.

Merci et bonne journée.
 

mapomme

XLDnaute Barbatruc
Supporter XLD
Bonjour @guiyom :), @_Thierry ;),

Pour le fun et vous saluer :) :
VB:
Private Sub UserForm_Initialize()
Dim t, n&, i&, j&, p&
   With Sheets("Feuil1")
      If .FilterMode Then .ShowAllData
      t = .Range("d11:L" & .Cells(.Rows.Count, "d").End(xlUp).Row)
      For i = 1 To UBound(t): n = n - (t(i, UBound(t, 2)) <> 0): Next
      If n > 0 Then ReDim r(1 To n, 1 To 9) Else Exit Sub
      For i = 1 To UBound(t)
         If t(i, UBound(t, 2)) <> 0 Then p = p + 1: For j = 1 To UBound(t, 2): r(p, j) = t(i, j): Next
      Next i
      ListBox1.List = r: ListBox1.TextAlign = fmTextAlignRight
   End With
End Sub
 

Pièces jointes

  • guiyom- init listbox- v1.xlsm
    26.2 KB · Affichages: 16

mapomme

XLDnaute Barbatruc
Supporter XLD
Re,

Une autre version toujours pour le fun :
VB:
Private Sub UserForm_Initialize()
Dim i&
   With Sheets("Feuil1")
      If .FilterMode Then .ShowAllData
      ListBox1.List = .Range("d11:L" & .Cells(.Rows.Count, "d").End(xlUp).Row).Value
      For i = ListBox1.ListCount - 1 To 0 Step -1
         If ListBox1.List(i, 8) = 0 Then ListBox1.RemoveItem i
      Next i
      ListBox1.TextAlign = fmTextAlignRight
   End With
End Sub
 

Pièces jointes

  • guiyom- init listbox- v2.xlsm
    26 KB · Affichages: 35

Discussions similaires

Réponses
17
Affichages
760