[RESOLU]Limiter l'ajout des donnees dans un tableau via usf

Ilino

XLDnaute Barbatruc
Bonjour Forum
dans mon USF de saisie, j'ai un bouton (nommé Ajouter) ce dernier son role de remplir un tableau via les TextBox et ComboBox
Code:
Private Sub CommandButton1_Click() ' Bouton Ajouter

Dim c As Control
For Each c In UserForm1.Controls
Select Case TypeName(c)
Case "TextBox", "ComboBox"
If Len(c.Value) = 0 Then
c.Enabled = True
c.BackColor = RGB(255, 0, 0)
MsgBox "Merci de completer les zones manquantes!"
c.SetFocus
Exit Sub
End If
End Select
Next c
MsgBox "Votre saisie est maintenant complète"



Ligne = Sheets("FSEx 2014").Range("a65500").End(xlUp).Row + 1
Sheets("FSEx 2014").Cells(Ligne, 1) = ComboBox1.Value
Sheets("FSEx 2014").Cells(Ligne, 2) = ComboBox6.Value
Sheets("FSEx 2014").Cells(Ligne, 3) = ComboBox2.Value
Sheets("FSEx 2014").Cells(Ligne, 8) = ComboBox3.Value
Sheets("FSEx 2014").Cells(Ligne, 6) = ComboBox4.Value
Sheets("FSEx 2014").Cells(Ligne, 7) = ComboBox5.Value
Sheets("FSEx 2014").Cells(Ligne, 4) = intitulétextbox.Value
Sheets("FSEx 2014").Cells(Ligne, 5) = statuttextbox.Value
Sheets("FSEx 2014").Cells(Ligne, 9) = TextBox1.Value
Sheets("FSEx 2014").Cells(Ligne, 12) = TextBox2.Value


ComboBox6 = ""
ComboBox2 = ""
ComboBox3 = ""
ComboBox4 = ""
ComboBox5 = ""
intitulétextbox = ""
statuttextbox = ""
TextBox1 = ""
TextBox2 = ""
'TextBox3 = ""

UserForm1.ComboBox1.Value = ""
UserForm1.CommandButton1.Visible = False
UserForm1.ComboBox1.RowSource = "A2:A" & [A65000].End(xlUp).Row

Unload UserForm1

End Sub
et comme dans mon USF de saisie j'ai d'autre TextBox et ComboBox , je souhaite limiter ce code aux TextBOX et combobox qui sont defini dans ce code seulement ?

je sais que a ce niveau la ( si je me trompe pas)
Code:
For Each c In UserForm1.Controls
Select Case TypeName(c)
Case "TextBox", "ComboBox"
If Len(c.Value) = 0 Then
que je dois changer mais j'ai pas pu le faire
GRAZIE par avance
 
Dernière édition:

laetitia90

XLDnaute Barbatruc
Re : Limiter l'ajout des donnees dans un tableau via usf

bonjour tous :)

il faut etre plus simple possible

dans ton code

Code:
ComboBox6 = ""
ComboBox2 = ""
ComboBox3 = ""
ComboBox4 = ""
ComboBox5 = ""
intitulétextbox = ""
statuttextbox = ""
TextBox1 = ""
TextBox2 = ""
'TextBox3 = ""

UserForm1.ComboBox1.Value = ""
UserForm1.CommandButton1.Visible = False
UserForm1.ComboBox1.RowSource = "A2:A" & [A65000].End(xlUp).Row

sert a rien du moment que tu ferme ton user a la fin???



autrement une methode bien simple dans chaque control tu as une proprieté interessante TAG

tu peus t'en servir exemple

Code:
Private Sub CommandButton1_Click()
 Dim c As Control, ligne As Long, x
 With Feuil2
 ligne = .Range("A" & Rows.Count).End(3).Row + 1
 For Each c In Controls
 If c.Tag <> "" And c = "" Then
 c.BackColor = RGB(255, 0, 0)
 MsgBox "Merci de completer les zones manquantes!"
 c.SetFocus
 Exit Sub
 End If
  If c.Tag <> "" And c <> "" Then
  x = CDbl(c.Tag)
 .Cells(ligne, x) = c.Value
 End If
 Next c
End With
MsgBox "copy ok"
 Unload Me
End Sub

que dis ce code.... deja j'utilise le codename de la feuille ou je dois copier

j'ai mis une info dans chaque controls que je dois copier mais vu que tu copy pas forcement dans la chrono... des colonnes autant exploiter egalement TAG

exemple

Cells(Ligne, 2) = ComboBox6.Value

donc TAG du combo6=2

.Cells(Ligne, 12) = TextBox2.Value

donc TAG du textbox2=12

ect...

tout les autres controls non concerne par la copy le tag reste vide
 

Discussions similaires

Statistiques des forums

Discussions
312 196
Messages
2 086 092
Membres
103 116
dernier inscrit
kutobi87