VBA : Ecriture sur la mauvaise feuille

mzalbil -  
f894009 Messages postés 17417 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour, je ne pense pas que mon erreurs soit grosse mais, je souhaiterais écrire quelques choses sur une feuille "cotisation" depuis un formulaire, sauf, que le formulaire écrit mes données directement sur la case sélectionnée et non là ou je le souhaite. (PS : la case sélectionnée est une case appartenant à une page ou il y a tout mes boutons)

Le code en question :
Private Sub Validercotisation_Click()
Dim i As Integer
If ajoutcotisation.Nom = "" Or ajoutcotisation.prenom = "" Or ajoutcotisation.Email = "" Or ajoutcotisation.sommecotisation = "" Then
Else
i = 2
Do While Worksheets("cotisation").Cells(i, 1) <> ""
Cells(i, 1).Offset(1, 0).Select
i = i + 1
Loop
ActiveCell.Value = ajoutcotisation.Nom.Value
ActiveCell.Offset(0, 1) = ajoutcotisation.prenom.Value
ActiveCell.Offset(0, 2) = ajoutcotisation.dateinscription.Value
ActiveCell.Offset(0, 3) = ajoutcotisation.Email.Value
ActiveCell.Offset(0, 4) = ajoutcotisation.sommecotisation.Value
Unload ajoutcotisation
End If
End Sub


merci d'avance pour votre aide !

1 réponse

  1. f894009 Messages postés 17417 Date d'inscription   Statut Membre Dernière intervention   1 717
     
    Bonjour,

    Private Sub Validercotisation_Click()
        Dim PCV As Integer
        
        If ajoutcotisation.Nom <> "" And ajoutcotisation.prenom <> "" And _
            ajoutcotisation.Email <> "" And ajoutcotisation.sommecotisation <> "" Then
            With worksheest("cotisation")
                'premiere cellule vide colonne A
                PCV = .Range("A" & Rows.Count).End(xlUp).Row + 1
                .Range("A" & PCV) = ajoutcotisation.Nom.Value
                .Range("B" & PCV) = ajoutcotisation.prenom.Value
                .Range("C" & PCV) = ajoutcotisation.dateinscription.Value
                .Range("D" & PCV) = ajoutcotisation.Email.Value
                .Range("E" & PCV) = ajoutcotisation.sommecotisation.Value
            End With
            Unload ajoutcotisation
        End If
    End Sub
    0