• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

Kolommen vullen in ListBox

Status
Niet open voor verdere reacties.

wieter

Terugkerende gebruiker
Lid geworden
26 jun 2009
Berichten
1.128
Gegroet,
Info over de bijlage: Klik op lege cel in kolomA = UserForm1
Dubbelklik op NIET-lege cel in kolomA = UserForm2

Het probleem stelt zich in Uform2.
Dit loopt goed tot kolom 11 van de ListBox moet gevuld worden, dan verschijnt een foutmelding.
In de rode regel loopt het vast.
Code:
Private Sub CommandButton1_Click()
    With ListBox1
        .Clear
        .ColumnCount = 15
        .ColumnWidths = "70;70;70;70;70;70;70;70;70;70;70;70;70;70;70"
        .ColumnHeads = False
    End With
    With Sheets(1)
        Rij = .Range("A" & .Rows.Count).End(xlUp).Row
        For r = 2 To Rij
            If .Cells(r, 2).Value = ComboBox2.Value Then
                ListBox1.AddItem .Cells(r, 1).Value
                ListBox1.List(s, 1) = .Cells(r, 2).Value
                ListBox1.List(s, 2) = .Cells(r, 3).Value
                ListBox1.List(s, 3) = .Cells(r, 4).Value
                ListBox1.List(s, 4) = .Cells(r, 5).Value
                ListBox1.List(s, 5) = .Cells(r, 6).Value
                ListBox1.List(s, 6) = .Cells(r, 7).Value
                ListBox1.List(s, 7) = .Cells(r, 8).Value
                ListBox1.List(s, 8) = .Cells(r, 9).Value
                ListBox1.List(s, 9) = .Cells(r, 10).Value
                [COLOR="#FF0000"]'ListBox1.List(s, 10) = .Cells(r, 11).Value[/COLOR]
                s = s + 1
            End If
        Next r
    End With
End Sub
Iemand dit de fout weet?

Bekijk bijlage (2)Uform tonen bij selectionchange.xlsm
 
Misschien helpt volgende quote verklaren waarom dit niet lukt:
A VBA ListBox will not display more than 10 columns of data unless you link the ListBox to Range using the "RowSource" property

If you populate the listbox with a variant array the column limit can be over-ridden.
Your issue then becomes creating a variant array from the filtered data.
 
Zie bijlage.

Je kan de knop 'Zoeken' verwijderen.
Zodra je combobox1 of combobox2 wijzigt, zie je direct resultaat.
 

Bijlagen

En dan mag je de code voor de combobox1 nog aanpassen naar:
Het rode gedeelte, het ander gedeelte is van jezelf en heb daar geen aandacht aan geschonken of het anders kan.

Private Sub ComboBox1_Change()
Code:
 [COLOR=#FF0000]
ComboBox2.ListIndex = -1
With ListBox1
  .List = Sheets(1).Cells(1).CurrentRegion.Value
     For i = .ListCount - 1 To 0 Step -1
       If Not .List(i, 0) = ComboBox1.Value Then .RemoveItem (i)
     Next i
  End With[/COLOR]
If ComboBox1.Value = Sheets(2).Cells(3, 1).Value Then
    ComboBox2.List = Sheets(2).Cells(3, 3).CurrentRegion.Value
End If
If ComboBox1.Value = Sheets(2).Cells(4, 1).Value Then
    ComboBox2.List = Sheets(2).Cells(3, 5).CurrentRegion.Value
End If
If ComboBox1.Value = Sheets(2).Cells(5, 1).Value Then
    ComboBox2.List = Sheets(2).Cells(3, 7).CurrentRegion.Value
End If
If ComboBox1.Value = Sheets(2).Cells(6, 1).Value Then
    ComboBox2.List = Sheets(2).Cells(3, 9).CurrentRegion.Value
End If
End Sub
 
Laatst bewerkt:
Code:
Private Sub ComboBox1_Change()
    With ListBox1
        .List = Sheets(1).Cells(1).CurrentRegion.Value
        For i = .ListCount - 1 To 0 Step -1
            If Not .List(i, 0) = ComboBox1.Value Then .RemoveItem (i)
        Next i
    End With
    With ComboBox2
        .ListIndex = -1
        .List = Sheets(2).Cells(3, Sheets(2).Rows(1).Find(ComboBox1.Value).Column).CurrentRegion.Value
    End With
End Sub
 
Laatst bewerkt:
Tja, dat krijg je dan als de "Mega Honourable Seniors" zich even op een probleem zetten.
Het zal heel wat zoekwerk vergen om alles te doorgronden.
Maar dat is uiteraard de bedoeling.
Bedankt Rudi, Harry, SNB
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan