IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Format de date textbox vers cellule


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    technicien BE plasturgie
    Inscrit en
    Mars 2018
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : technicien BE plasturgie
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2018
    Messages : 22
    Par défaut Format de date textbox vers cellule
    Bonjour,
    Sur mon fichier, j'avais un DTpicker, que j'ai du retirer car il ne fonctionnait pas sur un poste (win8 ,64 bits, mais sans le repertoire syswow64!), bref, on doit rentrer la date manuellement, ma macro la recupere et la transforme avant de la coller dans la cellule.
    aarrgghhhh
    je suis en format jj/mm/aaaa dans excel, et apres la macron la date est mm/jj/aaaa.
    j'ai cherché une solution, mais toutes celle que j'ai essayées ne marchent pas. je suis perdu (encore me direz vous)

    Quelle commande dois je ajouter pour retrouver ma date au bon format?

    mon code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    Option Explicit
     
    Dim Ws As Worksheet
    Dim NbLignes As Integer
     
     
     
     
     
    Private Sub ComboBox4_Change() 'combobox sous produit
    Dim plage As Range
    Set plage = Sheets("LISTE").Range("G2:F20")
    End Sub
     
    Private Sub ComboBox5_Change() 'Combobox activité
    Dim plage As Range
    Set plage = Sheets("LISTE").Range("A2:A90")
     
    End Sub
     
     
    Private Sub ComboBox3_Change() 'Combobox produit
    Dim plage As Range
    Set plage = Sheets("LISTE").Range("F2:F99")
     
    End Sub
     
     
    Private Sub ComboBox6_Change() 'Combobox intervenant
    Dim plage As Range
    Set plage = Sheets("LISTE").Range("E2:E15")
    End Sub
     
    Private Sub ComboBox7_Change() 'Combobox bateaux
    If ComboBox7.Value = "" Then Exit Sub
    Dim NomRange As String
    NomRange = CaracSpec(ComboBox7.Value)
     
    End Sub
     
    Private Sub CommandButton1_Click()
    Unload UserForm1
    End Sub
     
    Private Sub CommandButton2_Click()
    'Recuperation de la derniere ligne et inscription des données
    Dim intLine As Integer
     intLine = Range("a65000").End(xlUp).Row + 1
     
      Cells(intLine, 1).Value = TextBox2.Value
      Cells(intLine, 2).Value = ComboBox1.Value
      Cells(intLine, 3).Value = ComboBox2.Value
      Cells(intLine, 4).Value = ComboBox3.Value
      Cells(intLine, 5).Value = ComboBox4.Value
      Cells(intLine, 6).Value = ComboBox5.Value
      Cells(intLine, 7).Value = ComboBox6.Value
      Cells(intLine, 8).Value = TextBox1.Value
      Cells(intLine, 13).Value = TextBox4.Value
      Cells(intLine, 14).Value = TextBox5.Value
      intLine = Sheets("DONNEES " & ComboBox6.Value).Range("a65000").End(xlUp).Row + 1
       With Sheets("DONNEES " & ComboBox6.Value)
      .Cells(intLine, 1).Value = TextBox2.Value
      .Cells(intLine, 2).Value = ComboBox1.Value
      .Cells(intLine, 3).Value = ComboBox2.Value
      .Cells(intLine, 4).Value = ComboBox3.Value
      .Cells(intLine, 5).Value = ComboBox4.Value
      .Cells(intLine, 6).Value = ComboBox5.Value
      .Cells(intLine, 7).Value = ComboBox6.Value
      .Cells(intLine, 8).Value = TextBox1.Value
      End With
     
    End Sub
     
    Private Sub ListBox1_Click()
     
    End Sub
     
    Private Sub Label10_Click()
     
    End Sub
     
    Private Sub Label13_Click()
     
    End Sub
     
    Private Sub Label7_Click()
     
    End Sub
     
     
    Private Sub UserForm_Initialize()
            'Définit la feuille contenant les données
       Set Ws = Worksheets("client_bateaux2")
        'Définit le nombre de lignes dans la colonne A
    NbLignes = Ws.Range("A65536").End(xlUp).Row
        'Remplissage du ComboBox1
        Alim_Combo 1
     
    End Sub
     
    Private Sub Label1_Click()
     
    End Sub
     
    Private Sub Label5_Click()
     
    End Sub
     
    Private Sub TextBox1_Change()
     
    End Sub
     
    Private Sub TextBox2_Change()
     
    End Sub
     
     
    Private Sub UserForm_Click()
     
    End Sub
     
    Private Sub ComboBox1_Change() 'Combobox client
        'Remplissage Combo2
        Alim_Combo 2, ComboBox1.Value
    End Sub
     
     
    'Procédure pour alimenter les ComboBox
    Private Sub Alim_Combo(CbxIndex As Integer, Optional Cible As Variant)
        Dim j As Integer
        Dim Obj As Control
     
        'Définit le ComboBox à remplir
        Set Obj = Me.Controls("ComboBox" & CbxIndex)
        'Supprime les anciennes données
        Obj.Clear
     
        'alimente le Combobox initial (Combobox1)
        If CbxIndex = 1 Then
            'Boucle sur les lignes de la colonne A (à partir de la 2eme ligne)
            For j = 2 To NbLignes
                Obj = Ws.Range("A" & j)
                'Remplit le ComboBox sans doublons
                If Obj.ListIndex = -1 Then Obj.AddItem Ws.Range("A" & j)
            Next j
        Else
            'Alimentation conditionnelle des autres Combobox en fonction de
            'ce qui est sélectionnée dans le contrôle précédent:
            '(La sélection du ComboBox1 définit le contenu du ComboBox2,
            For j = 2 To NbLignes
                If Ws.Range("A" & j).Offset(0, CbxIndex - 2) = Cible Then
                    Obj = Ws.Range("A" & j).Offset(0, CbxIndex - 1)
                    If Obj.ListIndex = -1 Then Obj.AddItem Ws.Range("A" & j).Offset(0, CbxIndex - 1)
                End If
            Next j
       End If
     
       'Enlève la sélection dans le ComboBox
       Obj.ListIndex = -1
    End Sub
    Private Sub ComboBox2_click()
     
    End Sub

    Si vous avez une idée, je suis preneur

  2. #2
    Expert confirmé Avatar de BENNASR
    Homme Profil pro
    Responsable comptable & financier
    Inscrit en
    Décembre 2013
    Messages
    2 974
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable comptable & financier
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2013
    Messages : 2 974
    Par défaut
    bonsoir
    la quelle de tes textbox qui enregistre la date??
    et si tu essaye avec CDATE
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Cells(1, 1) = CDate(TextBox1.Value)

  3. #3
    Membre averti
    Homme Profil pro
    technicien BE plasturgie
    Inscrit en
    Mars 2018
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : technicien BE plasturgie
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2018
    Messages : 22
    Par défaut
    Bonsoir,
    Bennasr , c'est la textbox2, dans laquelle je renseigne la date.
    le CDate, je le glisse la? (sur tous les forums que j'ai epluché, je n'ai pas reussis a voir ou mettre les commandes proposées, j'ai fait plusieurs tests, mais échecs cuisants ^^ )

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Private Sub TextBox2_Change()
    Cells(1, 1) = CDate(TextBox2.Value)
    End Sub

    et Mfoxy, c'est a ce niveau la que l'ecriture se fait, dans les cellules concernées
    *edit*
    la cellule de destination est bien au format date jj/mm/aaaa

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    Private Sub CommandButton2_Click()
    'Recuperation de la derniere ligne et inscription des données
    Dim intLine As Integer
     intLine = Range("a65000").End(xlUp).Row + 1
     
      Cells(intLine, 1).Value = TextBox2.Value ' je recupere ma date sur la feuille principale
      Cells(intLine, 2).Value = ComboBox1.Value
      Cells(intLine, 3).Value = ComboBox2.Value
      Cells(intLine, 4).Value = ComboBox3.Value
      Cells(intLine, 5).Value = ComboBox4.Value
      Cells(intLine, 6).Value = ComboBox5.Value
      Cells(intLine, 7).Value = ComboBox6.Value
      Cells(intLine, 8).Value = TextBox1.Value
      Cells(intLine, 13).Value = TextBox4.Value
      Cells(intLine, 14).Value = TextBox5.Value
      intLine = Sheets("DONNEES " & ComboBox6.Value).Range("a65000").End(xlUp).Row + 1
       With Sheets("DONNEES " & ComboBox6.Value)
      .Cells(intLine, 1).Value = TextBox2.Value ' la je duplique sur chaque feuille (1 par personne remplissant le formulaire)
      .Cells(intLine, 2).Value = ComboBox1.Value
      .Cells(intLine, 3).Value = ComboBox2.Value
      .Cells(intLine, 4).Value = ComboBox3.Value
      .Cells(intLine, 5).Value = ComboBox4.Value
      .Cells(intLine, 6).Value = ComboBox5.Value
      .Cells(intLine, 7).Value = ComboBox6.Value
      .Cells(intLine, 8).Value = TextBox1.Value
      End With
     
    End Sub
    Et merci d'avoir répondu, je prends le fichier avec moi ce week end, faut que je debloque ça

  4. #4
    Expert confirmé Avatar de BENNASR
    Homme Profil pro
    Responsable comptable & financier
    Inscrit en
    Décembre 2013
    Messages
    2 974
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable comptable & financier
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2013
    Messages : 2 974
    Par défaut
    essayer avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Cells(intLine, 1).Value = CDate(TextBox2.Value)
    Cells(intLine, 1).NumberFormat = "m/d/yyyy"

  5. #5
    Inactif  

    Homme Profil pro
    cuisiniste
    Inscrit en
    Avril 2009
    Messages
    15 374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cuisiniste
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2009
    Messages : 15 374
    Billets dans le blog
    8
    Par défaut re
    bonsoir

    Citation Envoyé par BENNASR Voir le message
    essayer avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Cells(intLine, 1).NumberFormat = "m/d/yyyy"
    Cells(intLine, 1).Value = CDate(TextBox2.Value)
    BENNARS a raison il faut a plliquer le numberformat magique "m/d/yyyy"

    mais il faut le faire avant
    et si possible mettre un point devant cells si c'est dans un bloc with /end with ou le parent(sheets("blabla").cells(....).....)

    ou alors injecter dans la cells par dateserial

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    sheets(" le nom de ton sheets").Cells(intline, 1) = DateSerial(Year(TextBox2.Value), Month(TextBox2.Value), Day(TextBox2.Value))
    avec dateserial tu est tranquille
    peu importe l'ordre et le format dans le quel tu a taper ta date dans ton textbox la date sera dans le bon format (de ta region) dans la cellule
    et le must tu pourra constater dans le menu (format cellule ,nombre,date ) que le format appliqué est le francais (ou celui de ton system)
    autrement dit elle s'est formatée toute seule cool non?
    mes fichiers dans les contributions:
    mail avec CDO en vba et mail avec CDO en vbs dans un HTA
    survol des bouton dans userform
    prendre un cliché d'un range

    si ton problème est résolu n'oublie pas de pointer : : ça peut servir aux autres
    et n'oublie pas de voter

  6. #6
    Membre averti
    Homme Profil pro
    technicien BE plasturgie
    Inscrit en
    Mars 2018
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : technicien BE plasturgie
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2018
    Messages : 22
    Par défaut
    Bonsoir, merci pour vos réponses, mais, je ne pas a quel endroit placer ces lignes mes connaissances en vba sont limitées.
    Désolé.

    *edit*

    j'ai trouvé

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    Private Sub CommandButton2_Click()
    'Recuperation de la derniere ligne et inscription des données
    Dim intLine As Integer
     intLine = Range("a65000").End(xlUp).Row + 1
     
     
      Cells(intLine, 1) = DateSerial(Year(TextBox2.Value), Month(TextBox2.Value), Day(TextBox2.Value)) ' ajouté ici
      Cells(intLine, 2).Value = ComboBox1.Value
      Cells(intLine, 3).Value = ComboBox2.Value
      Cells(intLine, 4).Value = ComboBox3.Value
      Cells(intLine, 5).Value = ComboBox4.Value
      Cells(intLine, 6).Value = ComboBox5.Value
      Cells(intLine, 7).Value = ComboBox6.Value
      Cells(intLine, 8).Value = TextBox1.Value
      Cells(intLine, 13).Value = TextBox4.Value
      Cells(intLine, 14).Value = TextBox5.Value
      intLine = Sheets("DONNEES " & ComboBox6.Value).Range("a65000").End(xlUp).Row + 1
       With Sheets("DONNEES " & ComboBox6.Value)
      .Cells(intLine, 1) = DateSerial(Year(TextBox2.Value), Month(TextBox2.Value), Day(TextBox2.Value))
      .Cells(intLine, 2).Value = ComboBox1.Value
      .Cells(intLine, 3).Value = ComboBox2.Value
      .Cells(intLine, 4).Value = ComboBox3.Value
      .Cells(intLine, 5).Value = ComboBox4.Value
      .Cells(intLine, 6).Value = ComboBox5.Value
      .Cells(intLine, 7).Value = ComboBox6.Value
      .Cells(intLine, 8).Value = TextBox1.Value
      End With
     
    End Sub
    Meci beaucoup, c'est parfait, operationnel pour les collegues lundi

    et je dirai meme

  7. #7
    Membre Expert Avatar de mfoxy
    Homme Profil pro
    Automation VBA
    Inscrit en
    Février 2018
    Messages
    752
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Belgique

    Informations professionnelles :
    Activité : Automation VBA
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Février 2018
    Messages : 752
    Par défaut
    Hello,


    ta cellule excel incriminée est bien dans le bon format date
    quelle ligne de code représente l'import de la date et l'export dans la cellule excel après traitement ?

Discussions similaires

  1. [XL-2003] Symbole de retour à la ligne apres copie de textbox vers cellule
    Par altra dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 17/09/2009, 13h12
  2. [E-07] TextBox vers cellules suivantes
    Par chrnoe dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 13/01/2009, 13h14
  3. données textbox vers cellules
    Par jo50160 dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 05/01/2009, 20h36
  4. Forcer le format des dates dans une cellule
    Par cchampion2fr dans le forum Macros et VBA Excel
    Réponses: 7
    Dernier message: 01/10/2008, 13h20
  5. [Dates] Format de date MySQL vers français
    Par tcompagnon dans le forum Langage
    Réponses: 4
    Dernier message: 17/07/2007, 13h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo