XL 2010 Bouton modifier

Mimi

XLDnaute Occasionnel
Bonjour à tous,
J'ai créé avec l'aide de ce super forum un petit carnet d'adresse qui jusque là marche bien.
Je voudrais "simplement" ajouter un bouton modifié et là je sèche.
Pouvez-vous me donner un petit coup de main
D'avance merci
Mimi
 

Pièces jointes

  • Recherche Nom Retour1.xlsm
    1 MB · Affichages: 53

grisan29

XLDnaute Accro
bonjour Mimi
je ne me sens pas de pouvoir t'aider comme le ferai l'exellent dranreb :)avec ses ckxliées, ce que je vais te donner comme code est juste de forcer l'écriture des numéros de téléphone, fax etc a 10 chiffres
Code:
Private Sub TextBox6_Change()
    Me.TextBox6.Value = Format(Me.TextBox6.Value, "00 00 00 00 00")
End Sub
Private Sub TextBox6_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    TextBox6.MaxLength = 10
End Sub
Private Sub TextBox7_Change()
    Me.TextBox7.Value = Format(Me.TextBox7.Value, "00 00 00 00 00")
End Sub
Private Sub TextBox7_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    TextBox7.MaxLength = 10
End Sub
Private Sub TextBox8_Change()
    Me.TextBox8.Value = Format(Me.TextBox8.Value, "00 00 00 00 00")
End Sub
Private Sub TextBox8_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    TextBox8.MaxLength = 10
End Sub

comme tu l'as déja fait avec ton textbox3
a ce propos tu devrai donner un nom a tes textbox pour savoir qui fait quoi dans le code comme tu l'as fait pour cville
et une indentation serai un plus
bon je te joints le classeur client que dranreb m'a concocter il y a quelque temps:)
 

Pièces jointes

  • Client a modules de classes.zip
    129.8 KB · Affichages: 41

Lone-wolf

XLDnaute Barbatruc
Bonsoir Mimi, Pascal :)

Resultat.TextBox1 = Feuil1.Cells(lig, 1) .Tu dis que tout fonctionne, mais où est-qu'il est le formulaire Resultat??

Pour la combo de recherche, supprime row source.

VB:
Private Sub UserForm_Activate()
ComboBox1 = ""
End Sub

Private Sub UserForm_Initialize()
Dim j As Integer
With Feuil1
For j = 2 To .Range("a65536").End(xlUp).Row
ComboBox1 = .Range("a" & j)
If ComboBox1.ListIndex = -1 Then ComboBox1.AddItem .Range("a" & j)
Next j
End With
End Sub

'Pour le formulaire Saisir

Private Sub UserForm_Initialize()
With ComboBox3
.AddItem "M."
.AddItem "Mme"
.AddItem "Mlle"
.AddItem "M. & Mme"
End With
End Sub
 

max.lander

XLDnaute Occasionnel
Bonsoir à tous, Mimi, Lone-wolf,Grisan29

Un petit test en PJ sans grosse modification (2 lignes de code), toute la ligne est supprimée et remplacée par les nouvelles données.

J'ai également ajouté les propositions de Lone-wolf.


A+
 

Pièces jointes

  • Recherche Nom Retour2.xlsm
    1 022.7 KB · Affichages: 48

Mimi

XLDnaute Occasionnel
Bonjour à tous,
l"exemple de max.lander est bien, le seul souci c'est qu'il supprime la ligne pour la remettre en dessous de la dernière ligne,
Lone-wolf l'userform résultat je ne m'en sert pas j'ai tout réuni sur le même (userform saisir).
En attendant peut-être une autre proposition pour le bouton modifier je vai voir de mon coter.
Merci beaucoup de votre patience
Mimi
 

Lone-wolf

XLDnaute Barbatruc
Bonjour Mimi,

Si tu parle du bouton de modification c'est bizarre. Les modifications s'effectue bien sur la 2ème ligne. De plus pourquoi dans ce cas tu met resultas.TextBox1 dans le formulaire saisir??? o_O .

Moi j'aurait commencé avec les colonne comme ceci:
N° Corr. - Nom Complet(concatené avec prénom et nom) - Titre (Mme - Mlle -M.) -Prénom - Nom - Adresse - CP - Ville - Tél - Fax - Mail - Site Web - Commentaire. Ensuite dans les propriétés de chaque contrôles à la ligne Tag

´tag.gif

Le 1 correspond à la colonne A - 2 à B - 3 à C etc. Et pour teminer

VB:
Private Sub UserForm_Initialize()
Dim derlig As Integer, x As Integer, ws As Worksheet

Set ws = Sheets("Feuil1")

With ws
For x = 2 To .Range("a65536").End(xlUp).Row
        ComboBox1 = .Range("a" & x)
        If ComboBox1.ListIndex = -1 Then ComboBox1.AddItem .Range("a" & x)
    Next x
    ComboBox1 = ""
End With
End Sub

Private Sub UserForm_Activate()
Me.Top = 100
Me.Left = Me.Left + 288

ComboBox1.Text = ""
TextBox2.SetFocus
End Sub

Private Sub TextBox3_Change() ' Affiche Nom et Prénom
If TextBox3 <> "" Then _
TextBox1 = TextBox2 & " " & TextBox3
End Sub

Private Sub TextBox3_AfterUpdate()
Dim ctrl As Control, i%, j%, col As Range, ws As Worksheet

On Error GoTo fin
Set ws = Sheets("Feuil1")
Set col = ws.Range("A:A")

If TextBox1 <> "" Then
With ws
     i = Application.Match(TextBox1.Text, col, 0)
            If .Cells(i, 1).Value = TextBox1.Value Then
            MsgBox "Le contact est déjà dans la liste.", , "CONTACTS"
    ComboBox1 = ""
For i = 1 To 9
Me.Controls("TextBox" & i) = ""
Next i
Else
Exit Sub
TextBox4.SetFocus
        End If
End With
End If
fin:
Exit Sub
End Sub

Private Sub CmdValider_Click()
Dim ctrl As Control, ws As Worksheet, cel As Range
Dim derlig As Integer, col As Integer, i As Long

Set ws = Sheets("Feuil1")

With ws
derlig = .Range("a65536").End(xlUp).Row + 1

For Each ctrl In Me.Controls
col = Val(ctrl.Tag)
If col > 0 Then
If Not IsNumeric(ctrl) Then
.Cells(derlig, col) = ctrl
Else
.Cells(derlig, col) = CDbl(ctrl)   'format numérique simple ex: 3124
End If
End If
Next ctrl
.Range("G2:H65000").NumberFormat = "000 000 00 00"   'Numéro téléphone et fax
.Range("A:I").Columns.AutoFit
.Range("A2:I65000").Sort [A2], xlAscending
End With

For i = 1 To 9
Me.Controls("TextBox" & i) = ""
Next
TextBox2.SetFocus
End Sub

Private Sub CmdRechercher_Click()
Dim ctrl As Control, i%, j%, col As Range, ws As Worksheet

Set ws = Sheets("Feuil1")
Set col = ws.Range("A:A")

With ws
    i = Application.Match(Me.ComboBox1.Text, col, 0)

    For Each ctrl In Controls
        If ctrl.Tag <> "" Then
            j = Val(ctrl.Tag)
            ctrl.Value = .Cells(i, j).Value
        End If
    Next ctrl
End With
TextBox7 = Format(TextBox7, "000 000 00 00")
TextBox8 = Format(TextBox8, "000 000 00 00")
End Sub

Private Sub CmdModifier_Click()
Dim ctrl As Control, i%, j%, reponse, col As Range, ws As Worksheet

reponse = MsgBox("Voulez-vous vraiment procéder aux modifications ?", vbYesNo, "CONTACTS")

Set ws = Sheets("Feuil1")
Set col = ws.Range("A:A")


If reponse = vbYes Then
With ws
    i = Application.Match(Me.ComboBox1.Text, col, 0)

    For Each ctrl In Controls
        If ctrl.Tag <> "" Then
            j = Val(ctrl.Tag)
            .Cells(i, j).Value = ctrl.Value
        End If
    Next ctrl
End With
Else
ComboBox1 = ""
For i = 1 To 9
Me.Controls("TextBox" & i) = ""
Next i
End If
TextBox2.SetFocus
End Sub

Private Sub CmdQuitter_Click()
ComboBox1 = ""
For i = 1 To 9
Me.Controls("TextBox" & i) = ""
Next i
Unload Me
End Sub
 
Dernière édition:

Lone-wolf

XLDnaute Barbatruc
Re,


il faut enlever + 1 ici: num = Sheets("Recap").Range("A65536").End(xlUp).Row

Supprimer le code du bouton 5 et mettre

num = Sheets("Recap").Range("A65536").End(xlUp).Row 'on part du bas de la colonne, on cherche
Sheets("Recap").Activate
With Sheets("Recap")
.Range("A" & num).Value = TextBox12.Value
.Range("B" & num).Value = ComboBox3.Value
.Range("C" & num).Value = TextBox1.Value
.Range("D" & num).Value = TextBox2.Value
.Range("E" & num).Value = TextBox3.Value
.Range("F" & num).Value = TextBox4.Value
.Range("G" & num).Value = CVille.Value
.Range("H" & num).Value = TextBox6.Value
.Range("I" & num).Value = TextBox7.Value
.Range("J" & num).Value = TextBox8.Value
.Range("K" & num).Value = TextBox9.Value
.Range("L" & num).Value = TextBox10.Value
.Range("M" & num).Value = TextBox11.Value
End With
Unload Saisir

C'est inutile d'appeler une macro quand on peut l'inserer directement dans le bouton.
 

Lone-wolf

XLDnaute Barbatruc
Je ne comprends pas. Tu n'as, pour l'instant, qu' une ligne écrite (ligne 2), comment est-ce possible d'éffacer la ligne 3 si tu n'as rien écrit??? Par-ce que pour inserer une ligne on écrit

Lig = Sheets("Recap").Range("A65536").End(xlUp).Row + 1

Et pour modifier
Lig = Sheets("Recap").Range("A65536").End(xlUp).Row

Donc, elle ne peux pas inserer des lignes.
 

Lone-wolf

XLDnaute Barbatruc
Re Mimi

Sinon comme ceci

VB:
Private Sub CommandButton5_Click()
With Sheets("Recap")
lig = Application.Match(ComboBox1, Columns(1), 0)
.Range("A" & lig).Value = TextBox12.Value
.Range("B" & lig).Value = ComboBox3.Value
.Range("C" & lig).Value = TextBox1.Value
.Range("D" & lig).Value = TextBox2.Value
.Range("E" & lig).Value = TextBox3.Value
.Range("F" & lig).Value = TextBox4.Value
.Range("G" & lig).Value = CVille.Value
.Range("H" & lig).Value = TextBox6.Value
.Range("I" & lig).Value = TextBox7.Value
.Range("J" & lig).Value = TextBox8.Value
.Range("K" & lig).Value = TextBox9.Value
.Range("L" & lig).Value = TextBox10.Value
.Range("M" & lig).Value = TextBox11.Value
End With
Unload Saisir
End Sub
 

Discussions similaires

Réponses
5
Affichages
402

Membres actuellement en ligne

Statistiques des forums

Discussions
312 963
Messages
2 093 996
Membres
105 906
dernier inscrit
aifa