XL 2010 alimenter plusieur textbox en fonction d'une combobox

murainesouspatate

XLDnaute Occasionnel
Bonjour à tous,
N'arrivant pas à effectuer un macro qui pourrait être simple, je me retourne vers vous tous afin de résoudre mon problème.
Dans le fichier ci-joint, je souhaite remplir mes textbox 1-2 et 6 en fonction de la valeur de ma combobox1,
puis de renseigner les textbox 3-4 ou 5 en fonction des versements perçus et renvoyer ces dernières infos dans mon tableau colonne L-M et N.
J'ai commencé la macro et après plusieurs essais rien ne fonctionne correctement.
Pourriez-vous me donner un coup de main et surtout m'expliquer ce qui ne vas pas.:(

Cordialement.
 

Pièces jointes

  • Facture test.xlsm
    172.8 KB · Affichages: 67

Dranreb

XLDnaute Barbatruc
Bonjour.
Essayez comme ça :
VB:
Option Explicit
Private LCou As Long, VLgn()

Private Sub UserForm_Initialize()
Dim T(), L As Long
T = Feuil17.[A2].Resize(Feuil17.[A1000000].End(xlUp).Row - 1).Value
For L = 1 To UBound(T, 1): T(L, 1) = CStr(T(L, 1)): Next L
Me.ComboBox1.List = T
End Sub

Private Sub ComboBox1_Change()
If Me.ComboBox1.MatchFound Then
   LCou = ComboBox1.ListIndex + 1
   VLgn = Feuil17.[A1:O1].Offset(LCou).Value
Else
   LCou = 0
   ReDim VLgn(1 To 1, 1 To 15): End If
Me.TextBox1.Text = VLgn(1, 4)
Me.TextBox2.Text = VLgn(1, 11)
Me.TextBox3.Text = VLgn(1, 12)
Me.TextBox4.Text = VLgn(1, 13)
Me.TextBox5.Text = VLgn(1, 14)
Me.TextBox6.Text = VLgn(1, 15)
End Sub
Ce qui n'allait pas surtout, c'est qu'il ne trouvait pas de correspondance entre les N°Facture numériques et le texte, même seulement formé de chiffres, de la ComboBox1.
 

Dranreb

XLDnaute Barbatruc
Essayez comme ça :
VB:
Option Explicit
Private PlgTablo As Range, LCou As Long, VLgn()

Private Sub UserForm_Initialize()
Actualiser
End Sub

Private Sub Actualiser()
Dim T(), L As Long
Set PlgTablo = Feuil17.Rows(2).Resize(Feuil17.[A1000000].End(xlUp).Row - 1, 15)
T = PlgTablo.Columns(1).Value
For L = 1 To UBound(T, 1): T(L, 1) = CStr(T(L, 1)): Next L
Me.ComboBox1.List = T
End Sub

Private Sub ComboBox1_Change()
If Me.ComboBox1.MatchFound Then
   LCou = ComboBox1.ListIndex + 1
   VLgn = PlgTablo.Rows(LCou).Value
Else
   LCou = 0
   ReDim VLgn(1 To 1, 1 To 15): End If
Me.TextBox1.Text = VLgn(1, 4)
For C = 2 To 6: Me("TextBox" & 2).Text = VLgn(1, C + 9)
End Sub

Private Sub CommandButton1_Click()
Dim C As Long
If LCou = 0 Then Exit Sub
For C = 3 To 5: VLgn(1, C + 9) = CCur(Me("TextBox" & 2).Text): Next
PlgTablo.Rows(LCou).Value = VLgn
End Sub
 

murainesouspatate

XLDnaute Occasionnel
Re,
j'ai beau recopier les lignes ci-dessu, mais cela ne fonctionne pas. J'ai une Erreur de compilation : Variable non définie.
En déclarant "C as LOng", cela ne marche toujours pas ! je ne sais plus quoi faire , je t'envoi le mesage d'erreur.
Je suis complètement largué..:confused:
 

Pièces jointes

  • macro.jpg
    macro.jpg
    147.9 KB · Affichages: 45

Dranreb

XLDnaute Barbatruc
Oups. Il manquait aussi :Next C derrière Me("TextBox" & 2).Text = VLgn(1, C + 9)

Edit: et puis il y a d'autres erreurs.
Je redonne tout:
VB:
Option Explicit
Private PlgTablo As Range, LCou As Long, VLgn()

Private Sub UserForm_Initialize()
Actualiser
End Sub

Private Sub Actualiser()
Dim T(), L As Long
Set PlgTablo = Feuil17.Rows(2).Resize(Feuil17.[A1000000].End(xlUp).Row - 1, 15)
T = PlgTablo.Columns(1).Value
For L = 1 To UBound(T, 1): T(L, 1) = CStr(T(L, 1)): Next L
Me.ComboBox1.List = T
End Sub

Private Sub ComboBox1_Change()
Dim C As Long
If Me.ComboBox1.MatchFound Then
  LCou = ComboBox1.ListIndex + 1
  VLgn = PlgTablo.Rows(LCou).Value
Else
  LCou = 0
  ReDim VLgn(1 To 1, 1 To 15): End If
Me.TextBox1.Text = VLgn(1, 4)
For C = 2 To 6: Me("TextBox" & C).Text = VLgn(1, C + 9): Next C
End Sub

Private Sub CommandButton1_Click()
Dim C As Long, Z As String
If LCou = 0 Then Exit Sub
For C = 3 To 5
  Z = Me("TextBox" & C).Text
  If IsNumeric(Z) Then VLgn(1, C + 9) = CCur(Z) Else VLgn(1, C + 9) = Empty
  Next C
PlgTablo.Rows(LCou).Value = VLgn
End Sub
 
Dernière édition:

murainesouspatate

XLDnaute Occasionnel
Je viens de tester, une erreur persiste....
Private Sub CommandButton1_Click()
Dim C As Long
If LCou = 0 Then Exit Sub
For C = 3 To 5: VLgn(1, C + 9) = CCur(Me("TextBox" & C).Text): Next C
PlgTablo.Rows(LCou).Value = VLgn
End Sub
je 'tenvoi l'imprim écran.....
 

Pièces jointes

  • MACRO2.jpg
    MACRO2.jpg
    120.2 KB · Affichages: 67

Discussions similaires

Membres actuellement en ligne

Aucun membre en ligne actuellement.

Statistiques des forums

Discussions
312 084
Messages
2 085 194
Membres
102 814
dernier inscrit
JLGalley