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 :

probleme de syntaxe [XL-2007]


Sujet :

Macros et VBA Excel

  1. #1
    Membre éclairé
    Homme Profil pro
    retraite
    Inscrit en
    Avril 2010
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : Espagne

    Informations professionnelles :
    Activité : retraite
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2010
    Messages : 325
    Par défaut probleme de syntaxe
    bonjour
    est il possible au lieu de with sheets("Janv") de mettre
    with sheets.... feuil. active, car j'utilise cette macro sur plusieurs feuilles, et cela n'ennui un peu d'alourdir ma macro en la recopiant X fois.
    si quelqu'un sait comment faire, merci a lui.
    chris

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    With Sheets("Janv")
        For i = 9 To 73
            .Range("B" & i) = 0
            If .Range("C" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
            If .Range("K" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
            If .Range("R" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
            If .Range("Y" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
        Next i
    End With

  2. #2
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Tu peux mettre la feuille en paramètre (Macro2 à mettre dans un module standard)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Sub Macro2(ws As Worksheet)
    Dim i As Integer
     
    With ws
        For i = 9 To 73
            .Range("B" & i) = 0
            If .Range("C" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
            If .Range("K" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
            If .Range("R" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
            If .Range("Y" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
        Next i
    End With
    End Sub
    l'appel sera en fonction des feuilles souhaitées
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Sub test()
    Dim Sh As Worksheet
     
    For Each Sh In Worksheets(Array("janv", "fevr", "mars"))
        Call Macro2(Sh)
    Next Sh
    end sub
    pas de MP sur des questions techniques svp

  3. #3
    Membre éclairé
    Homme Profil pro
    retraite
    Inscrit en
    Avril 2010
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : Espagne

    Informations professionnelles :
    Activité : retraite
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2010
    Messages : 325
    Par défaut syntaxe macro
    voici ma macro complete, comment je peux y integrer ton code.
    merci
    chris

    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
    Private Sub CommandButton1_Click()
       Application.ScreenUpdating = False
     
        If Controls("Textbox1") = "" Then
           MsgBox "Vous devez ABSOLUMENT indiquer Un Nom !", vbExclamation, _
           "ERREUR ... Entrez un Nom SVP !"
           Controls("Textbox1").SetFocus
        Exit Sub
        End If
     
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
        End With
        Selection.Merge
        Selection = UserForm1.Textbox1
        Unload UserForm1
        With Selection.Interior
            .Color = 65535
         End With
        With Selection.Font
            .ColorIndex = xlAutomatic
        Selection.Font.Bold = True
        End With
     
    'Sub Macro2(ws As Worksheet)
    '    Dim i As Integer
    'With ws
    With Sheets("Janv")
    ' With Worksheets(Array("Janv", "Fevr", "Mars"))
        For i = 9 To 73
            .Range("B" & i) = 0
            If .Range("C" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
            If .Range("K" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
            If .Range("R" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
            If .Range("Y" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
        Next i
    End With
    'With Sheets("Fevr")
    '    For i = 9 To 73
    '        .Range("B" & i) = 0
    '        If .Range("C" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
    '        If .Range("K" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
    '       If .Range("R" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
    '        If .Range("Y" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
    '    Next i
    'End With
       Application.ScreenUpdating = True
    Range("A1").Select
    End Sub

  4. #4
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Je ne sais pas ce que tu veux faire avec tes Select et Selection, la première partie à revoir
    J'ai regoupé les 2 procédures
    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
    Private Sub CommandButton1_Click()
    Dim Sh As Worksheet
    Dim i As Integer
     
    If Controls("Textbox1") = "" Then
       MsgBox "Vous devez ABSOLUMENT indiquer Un Nom !", vbExclamation, _
              "ERREUR ... Entrez un Nom SVP !"
       Controls("Textbox1").SetFocus
       Exit Sub
    End If
     
    Application.ScreenUpdating = False
    '#------------------------------------------A revoir
    With Selection
       .HorizontalAlignment = xlCenter
       .VerticalAlignment = xlCenter
    End With
    Selection.Merge
    Selection = UserForm1.Textbox1
    Unload UserForm1
    With Selection.Interior
       .Color = 65535
    End With
    With Selection.Font
       .ColorIndex = xlAutomatic
       Selection.Font.Bold = True
    End With
    '#--------------------------------------------------
    For Each Sh In Worksheets(Array("janv", "fevr", "mars"))
       With Sh
          For i = 9 To 73
             .Range("B" & i) = 0
             If .Range("C" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
             If .Range("K" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
             If .Range("R" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
             If .Range("Y" & i).Interior.Color = 65535 Then .Range("B" & i) = .Range("B" & i) + 0.25
          Next i
       End With
    Next Sh
    End Sub

  5. #5
    Membre éclairé
    Homme Profil pro
    retraite
    Inscrit en
    Avril 2010
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : Espagne

    Informations professionnelles :
    Activité : retraite
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2010
    Messages : 325
    Par défaut syntaxe macro
    super ca marche nikel.
    merci a toi, je vais pouvoir finir enfin.

  6. #6
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Non, pas encore
    Tu auras fini quand tu vire toutes les Select et Selection
    au lieu de ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    With Selection
       .HorizontalAlignment = xlCenter
       .VerticalAlignment = xlCenter
    End With
    mets
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    With Sheets(X).Range(Y)
       .HorizontalAlignment = xlCenter
       .VerticalAlignment = xlCenter
    End With

  7. #7
    Membre éclairé
    Homme Profil pro
    retraite
    Inscrit en
    Avril 2010
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : Espagne

    Informations professionnelles :
    Activité : retraite
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2010
    Messages : 325
    Par défaut syntaxe macro
    Bonjour mercatog

    merci pour toutes tes réponses,
    sur la dernière réponse, si j'ai bien compris le code, il faut que je donne le nom de l'onglet ainsi que la cellule.
    Or je souhaite que chaque fois que je sélectionne une zone dans la feuille, cela aligne en vertical et horizontal le nom entrez dans cette zone.
    est tu d'accord avec moi.

    merci au modérateur d'avoir mis les balises sur mes questions précedement posées, avec l' exemple qu' il m'a donné, c'est plus clair.
    chris

  8. #8
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Bonjour,
    Tu as un userform avec textbox1
    l'utilisateur sélection une plage, appel l'userform, saisit un nom, et valide.
    Le code mets une mise en forme de cette sélection et procède à la mise à jour de la colonne B de toutes tes feuilles mensuelles.

    La sélection du départ opérée par l'utilisateur est elle aléatoire ou suit une logique (par exemple la première cellule vide d'une feuille X)

    C'était ça ma remarque

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

Discussions similaires

  1. probleme de syntaxe sql dans VB
    Par njac dans le forum Requêtes et SQL.
    Réponses: 4
    Dernier message: 20/05/2005, 15h41
  2. [VB.NET] Probleme de syntaxe
    Par microthib dans le forum Windows Forms
    Réponses: 4
    Dernier message: 17/03/2005, 14h49
  3. probleme fonction syntaxe
    Par gIch dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 28/02/2005, 10h52
  4. [Débutante] Problèmes de syntaxe
    Par new_wave dans le forum Prolog
    Réponses: 4
    Dernier message: 02/11/2004, 19h39
  5. Problemes de syntaxe
    Par maahta dans le forum SQL Procédural
    Réponses: 3
    Dernier message: 01/10/2003, 14h40

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