Ja - men nærmere forklaring er måske nødvendig? - Er det du ønsker, at kunne flytte den enkelte ugedag i forhold til de øvrige dage indenfor den enkelte listeboks ved hjælp af en Op/Ned knap?
Koden i formularen er følgende: Dim lb1 As Variant, lb2 As Variant, lbNr As Byte, ix, lb As Byte Const max = 7 'antal elementer i LB - tilpasses Private Sub CommandButton1_Click() Dim resultat, f ListBox1.ListIndex = -1 ListBox2.ListIndex = -1
resultat = "Listbox1:" + vbCr For f = 0 To ListBox1.ListCount - 1 resultat = resultat + ListBox1.List(f) + vbCr Next f
resultat = resultat + vbCr + "Listbox2:" + vbCr For f = 0 To ListBox2.ListCount - 1 resultat = resultat + ListBox2.List(f) + vbCr Next f
MsgBox (resultat) End Sub Private Sub ListBox1_Click() ListBox2.ListIndex = -1
ix = ListBox1.ListIndex End Sub Private Sub listbox2_Click() ListBox1.ListIndex = -1
SpinButton1.Enabled = True lbNr = 2 ix = ListBox2.ListIndex SpinButton1.Enabled = True End Sub Private Sub SpinButton1_spinUp() Dim tekst As String, modi If lbNr = 1 Then rykOp Me.ListBox1 Else rykOp Me.ListBox2 End If End Sub Private Sub rykOp(liste As Control) If ix - 1 < 0 Then tekst = liste liste.RemoveItem ix liste.AddItem tekst liste.ListIndex = liste.ListCount - 1 Else tekst = liste
If ix <> liste.ListCount - 1 Then modi = 1 Else modi = 0 End If
liste.RemoveItem ix liste.AddItem tekst, ix - modi liste.ListIndex = ix - modi End If End Sub Private Sub SpinButton1_spindown() If lbNr = 1 Then rykNed Me.ListBox1 Else rykNed Me.ListBox2 End If End Sub Private Sub rykNed(liste As Control) If ix + 1 > liste.ListCount - 1 Then tekst = liste liste.RemoveItem ix ix = 0 liste.AddItem tekst, 0 liste.ListIndex = ix Else tekst = liste
If ix <> liste.ListCount - 1 Then modi = 1 Else modi = 0 End If
liste.RemoveItem ix liste.AddItem tekst, ix + modi liste.ListIndex = ix + modi End If End Sub Private Sub UserForm_activate() lb1 = Array("Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "Lørdag", "Søndag") lb2 = Array("Anders", "Peter", "Hanne", "Mette", "Søren", "Lotte", "Sofie", "Pernille")
lb = 0
dataTillistBoxe SpinButton1.Enabled = False End Sub Private Sub dataTillistBoxe() Dim f For f = 0 To 6 ListBox1.AddItem lb1(f) ListBox2.AddItem lb2(f) Next f End Sub
I tools-box i VBA - knappen med 2 pile - aflæs navn ved at pege på knappen.
Ellers er du velkommen til at få userformen tilsendt - mail: pb@supertekst-it.dk
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.