Format a l'ajout de données

G

GClaire

Guest
Bonjour a toutes et tous

Avec ce code qui me sert a valider des données (Merci a Didier MDF, Monique) :

Private Sub cmdValider_Click()
Dim informer, nbligne, nbligne2
If QtBox.Value = "" Then
informer = MsgBox("Qté obligatoire !", vbOKOnly, "Ajout impossible...")
Exit Sub
End If
With ActiveSheet
.Unprotect
nbligne = ActiveSheet.Range("G4")
nbligne = nbligne + 1
.Range("G4") = nbligne
nbligne2 = nbligne + 12
If OptionButton1 = True Then
.Range("B" & nbligne2) = "Entrée"
.Range("E" & nbligne2) = RefBox.Value
End If
If OptionButton2 = True Then
.Range("B" & nbligne2) = "Sortie"
.Range("E" & nbligne2) = cbxN°Lot.Value
End If
.Range("C" & nbligne2) = CDate(DateBox.Value)
.Range("D" & nbligne2) = FournisseurBox.Value
.Range("F" & nbligne2) = QtBox.Value
With Range("C13:C" & Range("C65536").End(xlUp).Row)
If .Row = 13 Then ' si on revient avant la 13e ligne ==> rien
Range("G13").Resize(.Rows.Count, 1).Formula = _
"=IF(E13="""","""",SUMPRODUCT((E$13:E13=E13)*" & _
"((B$13:B13=E$2)*F$13:F13-(B$13:B13=F$2)*F$13:F13)))"
End If
End With
.Range("H" & nbligne2) = txtN°_CI.Value
.Range("I" & nbligne2) = cbxOpérateur.Value
.Range("B" & nbligne2).Select
With Range(Cells(nbligne2, 2), Cells(nbligne2, 9))
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=$B" _
& CStr(nbligne2) & "=""Entrée"""
.FormatConditions(1).Interior.ColorIndex = 36
End With
.Protect
Unload AjoutLigne
End Sub

J'aurais voulu rajouter au moment de l'enoie dans ma feuille les format des données (Centré droite et gauche , Etc)

Donc je voulais faire comme suis, avant la fermeture de l'userForm : Unload AjoutLigne

With Range("B" & nbligne2)
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
End With

With Range("C" & nbligne2)
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With

With Range("D" & nbligne2)
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
End With

With Range("E" & nbligne2)
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With

With Range("F" & nbligne2)
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
End With

With Range("G" & nbligne2)
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
End With

With Range("H" & nbligne2)
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With

With Range("I" & nbligne2)
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
End With
End With

Et bien sur cela ne fonctionne pas.

Comment dois-je faire?

Merci, G'Claire
 
Y

Yeahou

Guest
Bonjour Gclaire

il faut que tu insères ta proc ici

.FormatConditions(1).Interior.ColorIndex = 36
End With
'ici, la proc
.Protect
Unload AjoutLigne
End Sub

et que tu ajoutes un point devant tous tes range. il mange d'ailleurs des points dans la procédure principale. Cela ne gène pas car les cellules sont dans la feuille active mais si tu désirais changer pour travailler sur une feuille autre, cela ne fonctionnerait plus.
d'ailleurs ta proc devrait planter car il manque un end with ici

.FormatConditions(1).Interior.ColorIndex = 36
End With
'ici, la proc
.Protect
End With 'ici le end with
Unload AjoutLigne
End Sub

Cordialement, A+
 

Statistiques des forums

Discussions
312 489
Messages
2 088 855
Membres
103 976
dernier inscrit
kaizertv2001@gmailcom