Aide pour saisie auto base excel

  • Initiateur de la discussion Initiateur de la discussion s2fruit
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

S

s2fruit

Guest
Bonjour le forum 😉
Mon précedent post n'ayant pas eu de solution 🙁 je modifie ma demande en la simplifiant le plus possible 😱
Je voudrais une piste, un début de code pour arriver à faire ce que je décris dans mon fichier exemple.
Je vous remercie pour votre aide 🙄
 
Dernière modification par un modérateur:
Re : Aide pour saisie auto base excel

Bonjour s2fruit,

Je voudrais une piste, un début de code (...)

Début pour UserForm1 :

Code:
Private Sub CommandButton1_Click()
Dim P As Range, i As Byte, x$
With [A3].CurrentRegion
  Set P = .Resize(1, 9).Offset(.Rows.Count)
End With
If P.Row > 4 Then P.Rows(0).Copy P 'pour les formats
For i = 1 To 9
  x = Controls("TextBox" & i)
  If IsDate(x) Then
    P(i) = CDate(x)
  Else
    P(i) = UCase(x) 'majuscules
  End If
Next
End Sub
Pour UserForm2 commencez déjà par créer la liste que vous voulez pour ComboBox1.

Nombreux exemples sur le forum.

Edit : salut camarchepas, moi je préfère ce fil car notre ami repart à zéro...

A+
 
Dernière édition:
Re : Aide pour saisie auto base excel

Re ,

Un up suffit , pas besoin de recreer une discussion, tu diminue tes chance d'avoir des réponses cohérantes, voir même des réponses tout court

Bonjour Garchimore 😉 ye chui decholé hihihiihhhihi ye ne voulais pas créer d'incident diplomatique... Promis ye ne recommencerai plou 🙄
Dites, vous n'auriez pas un trouc dans votre chapeau pour ma base ?

Merci JC je vais essayer votre début de piste 😱
 
Re : Aide pour saisie auto base excel

Pour récupérer le valeurs textes de ma base A3: I3 pour les Labels de mon USF

Private Sub UserForm1_Initialize()
Dim i As Byte
For i = 1 To 9: Controls("Label" & i) = Sheets("Feuil1").Cells(i + 0, 10): Next
End Sub

ça ne fonctionne pas 🙁
 
Re : Aide pour saisie auto base excel

Re,

Ne faites pas n'importe quoi 🙄

Les captions des Labels sont à renseigner manuellement, une fois pour toutes.

Maintenant dans UserForm2, pour obtenir la liste de ComboBox1 triée alphabétiquement :

Code:
Private Sub UserForm_Initialize()
Dim t, i&, n&, a$()
With [A3].CurrentRegion.Resize(, 1)
  If .Count = 1 Then Exit Sub
  If .Count = 2 Then ComboBox1.AddItem .Cells(2): Exit Sub
  t = .Offset(1).Resize(.Count - 1) 'matrice, plus rapide
End With
For i = 1 To UBound(t)
  If t(i, 1) <> "" Then
    n = n + 1
    ReDim Preserve a(1 To n)
    a(n) = t(i, 1)
  End If
Next
tri a, 1, UBound(a)
ComboBox1.List = a
End Sub

Sub tri(a, gauc, droi)       ' Quick sort
Dim ref, g, d, temp
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
    Do While a(g) < ref: g = g + 1: Loop
    Do While ref < a(d): d = d - 1: Loop
    If g <= d Then
      temp = a(g): a(g) = a(d): a(d) = temp
      g = g + 1: d = d - 1
    End If
Loop While g <= d
If g < droi Then Call tri(a, g, droi)
If gauc < d Then Call tri(a, gauc, d)
End Sub
A+
 
Re : Aide pour saisie auto base excel

Re,

Ne faites pas n'importe quoi 🙄

Les captions des Labels sont à renseigner manuellement, une fois pour toutes.

Maintenant dans UserForm2, pour obtenir la liste de ComboBox1 triée alphabétiquement :

Code:
Private Sub UserForm_Initialize()
Dim t, i&, n&, a$()
With [A3].CurrentRegion.Resize(, 1)
  If .Count = 1 Then Exit Sub
  If .Count = 2 Then ComboBox1.AddItem .Cells(2): Exit Sub
  t = .Offset(1).Resize(.Count - 1) 'matrice, plus rapide
End With
For i = 1 To UBound(t)
  If t(i, 1) <> "" Then
    n = n + 1
    ReDim Preserve a(1 To n)
    a(n) = t(i, 1)
  End If
Next
tri a, 1, UBound(a)
ComboBox1.List = a
End Sub

Sub tri(a, gauc, droi)       ' Quick sort
Dim ref, g, d, temp
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
    Do While a(g) < ref: g = g + 1: Loop
    Do While ref < a(d): d = d - 1: Loop
    If g <= d Then
      temp = a(g): a(g) = a(d): a(d) = temp
      g = g + 1: d = d - 1
    End If
Loop While g <= d
If g < droi Then Call tri(a, g, droi)
If gauc < d Then Call tri(a, gauc, d)
End Sub
A+

😉 Nickel JC pour le tri
Pour Les captions des Labels je cherchais une solution car quand tu 100 labels à renseigner....parfois c'est long 😡
Que penses tu de ce code ?

Dim L As Byte
Dim ws As Worksheet
Dim Tabtemp As Variant
Me.Caption = t


With Worksheets("Feuil1")

remplir_Tableau Tabtemp

Set Maplage = .Range("A3:i3")
For L = 1 To Maplage.Count
Me.Controls("Label" & L) = Maplage(L)
Next


End With
Me.TextBox1.SetFocus



End Sub

🙄
 
Re : Aide pour saisie auto base excel

Bonjour.

C'est UserForm_Initialize et non pas UserForm1_Initialize.

Un début de code :
VB:
Option Explicit
Dim PlgTablo As Range, VLgn(), LCou&

Private Sub UserForm_Initialize()
Dim T(), C&
Set PlgTablo = Feuil1.[A4:I4].Resize(Feuil1.[A60000].End(xlUp).Row - 3)
T = PlgTablo.Rows(0).Value
For C = 1 To 9: Me("Label" & C).Caption = T(1, C): Next C
Me.ComboBox1.List = PlgTablo.Columns("A").Value
End Sub

Private Sub ComboBox1_Change()
Dim C&
LCou = ComboBox1.ListIndex + 1
If LCou = 0 Then
   ReDim VLgn(1 To 1, 1 To 9)
   VLgn(1, 1) = UCase(ComboBox1.Text)
Else
   VLgn = PlgTablo.Rows(LCou).Value
   End If
For C = 1 To 9: Me("TextBox" & C).Text = VLgn(1, C): Next C
End Sub
 
Dernière édition:
Re : Aide pour saisie auto base excel

Re,

C'est mon jour de bonté, le code intégral dans UserForm2 :

Code:
Private Sub ComboBox1_Change()
Dim i&, j As Byte
If ComboBox1.ListIndex = -1 Then 'RAZ
  For j = 1 To 9
    Controls("TextBox" & j) = ""
  Next
  Exit Sub
End If
With [A3].CurrentRegion
  i = Application.Match(ComboBox1, .Columns(1), 0)
  For j = 1 To 9
    Controls("TextBox" & j) = .Cells(i, j).Text
  Next
End With
End Sub

Private Sub CommandButton1_Click() 'VALIDER
Dim i&, j As Byte, x$
If ComboBox1.ListIndex = -1 Then _
  ComboBox1 = "": ComboBox1.SetFocus: Exit Sub
With [A3].CurrentRegion
  i = Application.Match(ComboBox1, .Columns(1), 0)
  For j = 1 To 9
    x = Controls("TextBox" & j)
    If IsDate(x) Then
      .Cells(i, j) = CDate(x)
    Else
      .Cells(i, j) = UCase(x) 'majuscules
    End If
  Next
End With
x = UCase(TextBox1) 'mémorise
UserForm_Initialize
ComboBox1 = x
End Sub

Private Sub CommandButton2_Click() 'QUITTER
Unload Me
End Sub

Private Sub UserForm_Initialize()
Dim t, i&, n&, a$()
ComboBox1.Clear
With [A3].CurrentRegion.Resize(, 1)
  If .Count = 1 Then Exit Sub
  If .Count = 2 Then ComboBox1.AddItem .Cells(2): Exit Sub
  t = .Offset(1).Resize(.Count - 1) 'matrice, plus rapide
End With
For i = 1 To UBound(t)
  If t(i, 1) <> "" Then
    n = n + 1
    ReDim Preserve a(1 To n)
    a(n) = t(i, 1)
  End If
Next
tri a, 1, UBound(a)
ComboBox1.List = a
End Sub

Sub tri(a, gauc, droi)       ' Quick sort
Dim ref, g, d, temp
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
    Do While a(g) < ref: g = g + 1: Loop
    Do While ref < a(d): d = d - 1: Loop
    If g <= d Then
      temp = a(g): a(g) = a(d): a(d) = temp
      g = g + 1: d = d - 1
    End If
Loop While g <= d
If g < droi Then Call tri(a, g, droi)
If gauc < d Then Call tri(a, gauc, d)
End Sub
A+
 
Re : Aide pour saisie auto base excel

Re, salut Bernard,




Vous n'êtes pas réveillé ou vous avez besoin de lunettes ?

Pour les intimes moi c'est Gérard.

A+

1000 Pardons 😱😱😱 Gérard, 😱 à faire pleins de trucs à la fois........
Je vous remercie du fond du coeur pour votre aide et vos précieuses réponses.
Je vais essayer de tout mettre en forme et je reviens vers vous. 😉

Merci aussi à Dranreb 😉
 
Re : Aide pour saisie auto base excel

Re,

Pour peaufiner on peut supprimer les lignes dont la colonne A est vide.

Pour cela dans UserForm1 terminer la macro comme suit :

Code:
Private Sub CommandButton1_Click() 'VALIDER
'-----
Next
With Range("A5:A" & Rows.Count)
  On Error Resume Next
  .SpecialCells(xlCellTypeBlanks).EntireRow.Delete
  If [A4] = "" Then
    If Application.CountA(.Cells) Then
      Rows(4).Delete
    Else
      Rows(4) = ""
    End If
  End If
End With
End Sub
Et dans UserForm2 :

Code:
Private Sub CommandButton1_Click() 'VALIDER
'-----
x = UCase(TextBox1) 'mémorise
With Range("A5:A" & Rows.Count)
  On Error Resume Next
  .SpecialCells(xlCellTypeBlanks).EntireRow.Delete
  If [A4] = "" Then
    If Application.CountA(.Cells) Then
      Rows(4).Delete
    Else
      Rows(4) = ""
    End If
  End If
End With
UserForm_Initialize
ComboBox1 = x
End Sub
Nota : pour vos 2 boutons en Feuil1, choisir l'option "Ne pas déplacer ou dimensionner avec les cellules".

A+
 
Dernière édition:
Re : Aide pour saisie auto base excel

😉 Gérard, Bernard, Laetitia, JC et pardon pour ceux que j'oublie 🙄 aprés quelques essais 😱😱😱
j'arrive enfin vers le fichier souhaité 😉 mais je bute sur la fin avec un message d'erreur.
MERCI de votre aide et patience 😛
Amicalement.
 
Dernière modification par un modérateur:
Re : Aide pour saisie auto base excel

Bonjour à tous,

J'ai rajouté la création des Labels.

A+ à tous

MERCI BEAUCOUP 😉 JC
J'ai juste un soucis sur l'USF qui permet de modifier les infos de la base... il ne prend en compte qu'une modification d'un champs 🙁🙁🙁 on ne peut pas modifier plusieurs champs en même temps.
Sur quelle partie du code il faut rectifier 😕
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD
Assurez vous de marquer un message comme solution pour une meilleure transparence.

Discussions similaires

Réponses
4
Affichages
488
Retour