Modification de code

apdf1

XLDnaute Impliqué
Bonjour,

Voila je suis a la recherche d'une modification de code j'ai une listbox a 10 colonnes et j'ai mis un label pour m'afficher le nombre de Client répertorier dans mon tableau qui est sur ma feuille de B9 à K100.

Voila le code que j'ai mis.
Code:
[CODE]Dim IndexLig As Integer

'Choix combobox
Private Sub ComboBox1_Change()
Dim C As Range
Set C = Cells.Find(what:=Me.ComboBox1.Text, LookIn:=xlValues, lookat:=xlWhole)
Me.TextBox1 = Cells(C.Row, 3).Text 'nom
Me.TextBox2 = Cells(C.Row, 4).Text 'date
Me.TextBox3 = Cells(C.Row, 5).Text 'N° Facture
Me.TextBox4 = Cells(C.Row, 6).Text ' Adresse
Me.TextBox5 = Cells(C.Row, 7).Text 'CP
Me.TextBox6 = Cells(C.Row, 8).Text 'Ville
Me.TextBox7 = Cells(C.Row, 9).Text 'Tel
Me.TextBox8 = Cells(C.Row, 10).Text ' Fax
Me.TextBox9 = Cells(C.Row, 11).Text 'Mobile
Me.TextBox10 = Cells(C.Row, 2).Text 'Ref
 
End Sub


Private Sub UserForm_Initialize()
Dim maplage As Range, i As Integer
With ListBox1
    .ColumnCount = 10
    .ColumnHeads = True
    .RowSource = Range("B9:l" & Range("B65536").End(xlUp).Row).Address
End With
'Date et heure dans label11 2éme façon
Label10.Caption = "Nous somme le : " & Format(Now(), "dd mmmm yyyy") & ", il est " & Format(Now(), "hh : mm") & " heure"

 Dim aa As Variant
    aa = Feuil1.Range("c10:l" & Feuil1.Range("B65536").End(xlUp).Row)
    ComboBox1.List = aa


End Sub

Private Sub CommandButton1_Click()
Unload Me
End Sub

' Supprimer un client
Private Sub CommandButton2_Click()
Dim Fact As String, Lg As Long
Fact = TextBox3.Text
With Sheets("Feuil1")
  Lg = .Range("D:D").Find(Fact, LookIn:=xlValues).Row
  .Cells(Lg, 1).EntireRow.Delete
End With
UserForm_Initialize
Me.TextBox1.Value = ""
 Me.TextBox2.Value = ""
  Me.TextBox3.Value = ""
   Me.TextBox4.Value = ""
    Me.TextBox5.Value = ""
     Me.TextBox6.Value = ""
     Me.TextBox7.Value = ""
     Me.TextBox8.Value = ""
     Me.TextBox9.Value = ""
     Me.TextBox10.Value = ""
     
     UserForm1.Hide

End Sub

' Modifier l 'adresse d'un client
Private Sub CommandButton3_Click()
Dim k As Byte
With Sheets("FEUIL1")
For k = 1 To 10
.Cells(IndexLig, k + 1) = Controls("Textbox" & k)
Next k
End With
UserForm_Initialize
For k = 1 To 10
Controls("Textbox" & k) = ""
Next k
End Sub

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
With ListBox1
    TextBox1 = .List(.ListIndex, 1)
    TextBox2 = CDate(.List(.ListIndex, 2))
    TextBox3 = .List(.ListIndex, 3)
    TextBox4 = .List(.ListIndex, 4)
    TextBox5 = .List(.ListIndex, 5)
    TextBox6 = .List(.ListIndex, 6)
    TextBox7 = .List(.ListIndex, 7)
    TextBox8 = .List(.ListIndex, 8)
    TextBox9 = .List(.ListIndex, 9)
   TextBox10 = .List(.ListIndex, 0)
IndexLig = .ListIndex + 9
End With
  'Affiche le nombre de sélections dans l'USF
Label7.Caption = "Il y a.. " & ListBox1.ListCount & "  Client répertorier dans la listBox"
  'N° de ligne selectionner dans la listBox1
Label9 = "Et j'ai sélectionné la .. " & ListBox1.ListIndex + 0 & " éme ligne..!"     ' + 1 veut dire comme je commence à la ligne 2 pour avoir un chiffre

End Sub
Le problème il comptabilise se qu'il il a en dehors du tableau, c'est à dire en colonne B j'ai des formules qui descende jusqu'a la cellule 100, alors que les clients répertorier s'arrête en "A 19" il comptabilise même les formules.
Il y a t-il une solution pour lui dire qu'il comptabilise uniquement se qu'il y a dans le tableau en sachant que le tableau va s'agrandir tous les jours ?.

Bien cordialement

Max
 
Dernière édition:

job75

XLDnaute Barbatruc
Re : Modification de code

Bonjour Max, salut kjin,

J'imagine que sous votre tableau en colonne B il y a des formules renvoyant le texte vide "".

Malgré cela on peut définir une plage évolutive par une formule comme celle-ci :

=DECALER(Feuil1!$B$8;;;NB.SI(Feuil1!$B:$B;"?*")+1;6)

Dans le fichier joint (tiré d'une de vos discussions) j'ai défini le nom Tableau avec la formule précédente.

Nota : La RowSource de la ListBox1 est définie par [Tableau].Address

A+
 

Pièces jointes

  • ListboxSupprimerModifierBD2.zip
    20.4 KB · Affichages: 34

job75

XLDnaute Barbatruc
Re : Modification de code

Bonjour kjin, le fil,

Excuse-moi, j'ai peut-être exagéré en m'immisçant dans ta discussion, mais je connaissais le fichier...

Pour conclure ce fil, on peut initialiser la ListBox1 ainsi :

Code:
Private Sub UserForm_Initialize()
With ListBox1
    .ColumnCount = 6
    .ColumnHeads = True
    .RowSource = "Tableau"
End With
'-------
End Sub

De cette manière ListBox1 se met à jour automatiquement quand le tableau est modifié.

Fichier joint.

A+
 

Pièces jointes

  • ListboxSupprimerModifierBD2(1).xls
    42.5 KB · Affichages: 59

Discussions similaires

Réponses
1
Affichages
160
Réponses
17
Affichages
808

Statistiques des forums

Discussions
312 113
Messages
2 085 422
Membres
102 886
dernier inscrit
eurlece