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 :

condition dans une boucle [XL-2007]


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de bosk1000
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    706
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 706
    Par défaut condition dans une boucle
    Bonjour à tous,

    Dans une boucle de type for i=, je voudrais inclure une autre condition en if

    La boucle vient mettre des information sur les colonne de A jusqu'à I, issue d'une saisie sur un formulaire


    mon soucis est la colonne F ou je veux mettre inclure 3 informations
    les deux premières sont issue de l'addition de deux textbox ("txt_pv" et "txt_sacem") du formulaire
    la troisième dépend d'une information texte situé dans une combobox ("cmb_nom") selon le résultat, je voudrais ajouter 22 au résultat des 2 première textbox

    actuellement le code est celui-ci

    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
     
    Dim cmb_nom01 As String
    Dim cmb_nom02 As String
    Dim cmb_nom03 As String
    Dim cmb_nom04 As String
    Dim cmb_nom05 As String
    Dim cmb_nom06 As String
    Dim cmb_nom07 As String
    Dim cmb_nom08 As String
    Dim cmb_nom09 As String
    Dim cmb_nom10 As String
    Dim cmb_nom11 As String
    Dim cmb_nom12 As String
    Dim cmb_nom13 As String
    Dim cmb_nom14 As String
     
     
     
    On Error Resume Next
    'inscrire les noms en feuille n°de commande
     
    If Me.cmb_nom01.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom01
    If Me.cmb_nom02.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom02
    If Me.cmb_nom03.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom03
    If Me.cmb_nom04.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom04
    If Me.cmb_nom05.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom05
    If Me.cmb_nom06.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom06
    If Me.cmb_nom07.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom07
    If Me.cmb_nom08.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom08
    If Me.cmb_nom09.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom09
    If Me.cmb_nom10.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom10
    If Me.cmb_nom11.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom11
    If Me.cmb_nom12.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom12
    If Me.cmb_nom13.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom13
    If Me.cmb_nom14.Value <> "" Then Sheets("n°commande").Range("e65536").End(xlUp).Offset(1, 0) = Me.cmb_nom14
     
     
    Sheets("commandeelectro").Select
    Dim i As Byte, Indice As Byte, derlig As Integer
    With Worksheets("commandeelectro")
        derlig = .Range("A" & .Rows.Count).End(xlUp).Row
        For i = 1 To 14
            If Controls("cmb_nom" & Format(i, "00")) <> "" Then
                Indice = Indice + 1
     
     
     
     
                .Range("A" & Indice + derlig) = Controls("commande" & Format(i, "00"))
                .Range("b" & Indice + derlig) = Controls("cmb_nom" & Format(i, "00"))
                .Range("c" & Indice + derlig) = Controls("cmb_type" & Format(i, "00"))
                .Range("d" & Indice + derlig) = Controls("cmb_marque" & Format(i, "00"))
                .Range("e" & Indice + derlig) = Controls("txt_ref" & Format(i, "00"))
      End If
    j'ai essayé ceci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
                .if range("c" & Indice + derlig).Value ="Leger Garantie" then Range("q" & Indice + derlig)= controls("txt_pv" & Format(i, "00")) + Controls("txt_sacem" & Format(i, "00"))+22
    Mais j'obtiens le message attendu : fin d'instruction

    Merci pour votre aide

  2. #2
    Invité
    Invité(e)
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if .range("c" & Indice + derlig).Value ="Leger Garantie" then .Range("q" & Indice + derlig)= controls("txt_pv" & Format(i, "00")) + Controls("txt_sacem" & Format(i, "00"))+22

  3. #3
    Membre éclairé Avatar de bosk1000
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    706
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 706
    Par défaut
    super
    j'ai compris l'erreur

    merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Un probléme de condition dans une boucle
    Par boubz013 dans le forum Débuter
    Réponses: 6
    Dernier message: 22/02/2010, 15h52
  2. Condition dans une boucle for
    Par nicolasferraris dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 17/04/2009, 17h28
  3. Réponses: 3
    Dernier message: 12/03/2009, 18h08
  4. Appliquer un next sous conditions dans une boucle for
    Par Kibald dans le forum Macros et VBA Excel
    Réponses: 7
    Dernier message: 29/01/2009, 08h56
  5. [FLASH MX2004] Deux conditions dans une boucle
    Par pierrot10 dans le forum Flash
    Réponses: 1
    Dernier message: 06/11/2005, 16h31

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