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 :

Remplacer ProgressBar par Label


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre chevronné
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    473
    Détails du profil
    Informations personnelles :
    Localisation : France, Vendée (Pays de la Loire)

    Informations forums :
    Inscription : Novembre 2007
    Messages : 473
    Par défaut Remplacer ProgressBar par Label
    Bonjour le forum!

    Je viens vers vous, car j'ai un fichier qui va sur plusieurs poste! J'ai un ptit code qui fonctionne bien, mais comme vous allez le voir il peu demander un peu de temps! Pour faire patienter la personne j'ai mis un progressbar, mais le problème est que toutes les ordinateurs ne sont pas équipé pour celui-ci!

    Et comme le ne souhaite pas leurs proposer une installation de "component" je voulais faire un label en lui faisant augmenter sa longueur. ds mon exemple il s'intitule "LabPRB.Width"

    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
    Sub ReCherche_Ecritures()
    Dim DéBit, CréDit, SolDE As String
        DéBit = 0
        CréDit = 0
        SolDE = 0
        GL.ProB1 = 0
        LabPRB.Width = 0 ' label de progressbar
        GL.ProB1.Visible = True
        GL.Image1.Visible = True
     
     Dim NbLgne As Variant
        Dim i, j, Y As Integer
        Dim K, P
        Dim TesteR, Teste2 As Boolean
        Dim U As Byte
        GL.ListBox1.Clear
     
        NbLgne = Sheets("Récap ").Range("a65000").End(xlUp).Row
        'Sheets("feuil2").Range("b27") = NbLgne
    For i = 2 To NbLgne + 1
      ' on regarde pour les analyt
     TesteR = False
     If GL.ToUs = True Then
      TesteR = True
      GoTo fin1
      End If
     
     
     
         For Y = 0 To GL.ListBox3.ListCount - 1
     
            If Val(GL.ComptAnal.Value) = 0 And GL.TousAnal.Caption = "Sans analyt." And GL.ToUs = False Then
     
     
            If Cells(i, 5) = "" Then TesteR = True             Exit For
             End If
     
     
            If Val(GL.ComptAnal.Value) > 0 Then
     
            If GL.ListBox3.Selected(Y) = False Then TesteR = False
            If GL.ListBox3.Selected(Y) = True And Cells(i, 5) Like GL.ListBox3.List(Y) Then
                TesteR = True
                Exit For
            End If
     
     
     
            End If
          Next Y
    fin1:
     
     
          If Val(GL.comp.Value) > 0 Then
            For j = 0 To GL.ListBox2.ListCount - 1
            Teste2 = False
            If Cells(i, 9) = GL.ListBox2.List(j) Then
                Teste2 = True
     
                Exit For
                End If
     
              Next j
          End If
     
          If Val(GL.comp.Value) = 0 Then
            Teste2 = False
            If Cells(i, 9) = GL.ComboBox6.Value Then Teste2 = True
          End If
          If GL.ComboBox6.Text = "" Then Teste2 = True
     
    If Cells(i, 10) <> "" And Cells(i, 10) <> 0 And TesteR = True And Teste2 = True _
          And Cells(i, 9) Like UCase(GL.Tst1.Text) & "*" _
          And Cells(i, 1) Like UCase(GL.Tst3.Text) & "*" _
          And Cells(i, 12) Like UCase(GL.Tst4.Text) & "*" _
          And Cells(i, 6) Like "*" & UCase(GL.Tst2.Text) & "*" Then
           GL.ListBox1.AddItem
           GL.ListBox1.List(K, 0) = Sheets("Récap ").Cells(i, 2)
           GL.ListBox1.List(K, 1) = "| " & Sheets("Récap ").Cells(i, 3)
           GL.ListBox1.List(K, 2) = "| " & Sheets("Récap ").Cells(i, 5)
           GL.ListBox1.List(K, 3) = "| " & Sheets("Récap ").Cells(i, 6)
           GL.ListBox1.List(K, 4) = "| " & Sheets("Récap ").Cells(i, 7)
           GL.ListBox1.List(K, 5) = "| " & Sheets("Récap ").Cells(i, 9)
           GL.ListBox1.List(K, 6) = "| " & Sheets("Récap ").Cells(i, 8)
           GL.ListBox1.List(K, 7) = "| " & Sheets("Récap ").Cells(i, 30)
            DéBit = DéBit + Sheets("Récap ").Cells(i, 30)
           GL.ListBox1.List(K, 8) = "| " & Sheets("Récap ").Cells(i, 29)
            CréDit = CréDit + Sheets("Récap ").Cells(i, 29)
           GL.ListBox1.List(K, 9) = "| " & Sheets("Récap ").Cells(i, 4)
            K = K + 1
            'Sheets("feuil2").Range("c27") = i
            U = (i * 100) / NbLgne
           GL.ProB1 = U ' ICI le PROGRESSBAR
            LabPRB.Width = U ' ICI LE LABEL
        End If
        GL.ComptLigne = K
    Next i
    GL.TdéBit.Value = DéBit
    GL.TdéBit.Value = Format(GL.TCit.Value, "#,##0.00")
    GL.TcréDit.Value = CréDit
    GL.TcréDit.Value = Format(GL.TDit.Value, "#,##0.00")
    GL.TSolDe.Value = CréDit - DéBit
    GL.TSolDe.Value = Format(GL.TlDe.Value, "#,##0.00")
    GL.ProB1.Visible = False
    GL.Image1.Visible = False
    GL.ListBox1.ColumnWidths = "50;55;60;110;170;150;30;55;55;80"
     
    End Sub
    Je vs montre ce code juste pour mon problème de label mais les critiques sur celui-ci sont les bienvenu!

    Tous ce code pour dire que le label ne progresse pas !!!! Sauf lorsqu'il à fini sa recherche, par contre le progressbar fonctionne très bien !!

    avez vous une solution !

    Merci

    jijie

  2. #2
    Expert confirmé
    Avatar de kiki29
    Homme Profil pro
    ex Observeur CGG / Analyste prog.
    Inscrit en
    Juin 2006
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : ex Observeur CGG / Analyste prog.

    Informations forums :
    Inscription : Juin 2006
    Messages : 6 132
    Par défaut
    Salut, voir avec Repaint de l'UserForm ou alors nettement plus léger en codage via
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Application.StatusBar =
    ou l'on fera apparaitre le décompte d'une boucle.

  3. #3
    Membre chevronné
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    473
    Détails du profil
    Informations personnelles :
    Localisation : France, Vendée (Pays de la Loire)

    Informations forums :
    Inscription : Novembre 2007
    Messages : 473
    Par défaut
    Merci Kiki !

    OK plus léger ! mais comment ?

    jijie

  4. #4
    Expert confirmé
    Avatar de kiki29
    Homme Profil pro
    ex Observeur CGG / Analyste prog.
    Inscrit en
    Juin 2006
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : ex Observeur CGG / Analyste prog.

    Informations forums :
    Inscription : Juin 2006
    Messages : 6 132
    Par défaut
    Re, du style
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
        For i = 1 To Nb
            '.....
            Application.StatusBar = i & " / " & Nb
        Next i

  5. #5
    Membre chevronné
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    473
    Détails du profil
    Informations personnelles :
    Localisation : France, Vendée (Pays de la Loire)

    Informations forums :
    Inscription : Novembre 2007
    Messages : 473
    Par défaut
    re salut Kiki ,

    oui ça fonctionne ! mais le souci est que mon USER était en plein écran, et je ne voyais pas la barre !

    Sinon ça fonctionne! Malgré que ça ne me satisfait pas !

    Si il n'y a pas d'autre solution!? je continu à chercher !

    merci pour ton aide

  6. #6
    Expert confirmé
    Avatar de kiki29
    Homme Profil pro
    ex Observeur CGG / Analyste prog.
    Inscrit en
    Juin 2006
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : ex Observeur CGG / Analyste prog.

    Informations forums :
    Inscription : Juin 2006
    Messages : 6 132
    Par défaut
    Re, as-tu testé, comme suggéré dans Post# 2, avec

  7. #7
    Membre chevronné
    Homme Profil pro
    Inscrit en
    Juin 2011
    Messages
    181
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2011
    Messages : 181
    Par défaut
    Bonjour à tous,

    Avez-vous essayé la 1ère solution proposée par kiki, à savoir l'instruction "Repaint".

    Il suffirait donc d'écrire juste après l'instruction affectant une nouvelle largeur au label :
    En remplaçant "UserForm" par son Name.

    Cordialement.

  8. #8
    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 heu
    bonjour

    en fait il faut que tu fasse un petit calcul intelligent et dynamique

    tu a dans ton usf un label qui doit grandir (en largeur ) en fonction de l'avancement de la boucle avec "i"
    problème si ta boucle fait 300 lignes ton label va faire a la fin 300 certainement plus grand que le userform et c'est pas bon



    en fait il faut


    déterminer le maximum de largeur du label par rapport a ton usf
    et quand tu a déterminer le nombre de lignes avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    NbLgne = Sheets("Récap ").Range("a65000").End(xlUp).Row
    tu fait nbligne/largeurmaximum du label
    tu te retrouve avec un nombre que l'on va affiler a une variable "avancement " donc de type long
    et quand ta boucle incrémente "i" tu fait me.LabPRB.Width =(i/avancement)
    ainsi ton label va s'agrandir en fonction de l'avancement et proportionnellement de la tache qu'il reste a faire

    enfin:
    a supposer que ton la bel par exemple mesure 200 quand la sub est terminer

    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
    Sub ReCherche_Ecritures()
    Dim DéBit, CréDit, SolDE As String,avancement as long
        DéBit = 0
        CréDit = 0
        SolDE = 0
        GL.ProB1 = 0
        LabPRB.Width = 0 ' label de progressbar
        GL.ProB1.Visible = True
        GL.Image1.Visible = True
     
     Dim NbLgne As Variant
        Dim i, j, Y As Integer
        Dim K, P
        Dim TesteR, Teste2 As Boolean
        Dim U As Byte
        GL.ListBox1.Clear
     avancement=nbligne/200
        NbLgne = Sheets("Récap ").Range("a65000").End(xlUp).Row
        'Sheets("feuil2").Range("b27") = NbLgne
     
    For i = 2 To NbLgne + 1
      'si la sub se trouve dans le userform    
     LabPRB.Width = ((i-1)/avancement*)'tout simplement
    'si la sub ne se trouve pas dans le userform
    ' on regarde pour les analyt
     TesteR = False
     If GL.ToUs = True Then
      TesteR = True
      GoTo fin1
      End If
     
     
     
         For Y = 0 To GL.ListBox3.ListCount - 1
     
            If Val(GL.ComptAnal.Value) = 0 And GL.TousAnal.Caption = "Sans analyt." And GL.ToUs = False Then
     
     
            If Cells(i, 5) = "" Then TesteR = True             Exit For
             End If
     
     
            If Val(GL.ComptAnal.Value) > 0 Then
     
            If GL.ListBox3.Selected(Y) = False Then TesteR = False
            If GL.ListBox3.Selected(Y) = True And Cells(i, 5) Like GL.ListBox3.List(Y) Then
                TesteR = True
                Exit For
            End If
     
     
     
            End If
          Next Y
    fin1:
     
     
          If Val(GL.comp.Value) > 0 Then
            For j = 0 To GL.ListBox2.ListCount - 1
            Teste2 = False
            If Cells(i, 9) = GL.ListBox2.List(j) Then
                Teste2 = True
     
                Exit For
                End If
     
              Next j
          End If
     
          If Val(GL.comp.Value) = 0 Then
            Teste2 = False
            If Cells(i, 9) = GL.ComboBox6.Value Then Teste2 = True
          End If
          If GL.ComboBox6.Text = "" Then Teste2 = True
     
    If Cells(i, 10) <> "" And Cells(i, 10) <> 0 And TesteR = True And Teste2 = True _
          And Cells(i, 9) Like UCase(GL.Tst1.Text) & "*" _
          And Cells(i, 1) Like UCase(GL.Tst3.Text) & "*" _
          And Cells(i, 12) Like UCase(GL.Tst4.Text) & "*" _
          And Cells(i, 6) Like "*" & UCase(GL.Tst2.Text) & "*" Then
           GL.ListBox1.AddItem
           GL.ListBox1.List(K, 0) = Sheets("Récap ").Cells(i, 2)
           GL.ListBox1.List(K, 1) = "| " & Sheets("Récap ").Cells(i, 3)
           GL.ListBox1.List(K, 2) = "| " & Sheets("Récap ").Cells(i, 5)
           GL.ListBox1.List(K, 3) = "| " & Sheets("Récap ").Cells(i, 6)
           GL.ListBox1.List(K, 4) = "| " & Sheets("Récap ").Cells(i, 7)
           GL.ListBox1.List(K, 5) = "| " & Sheets("Récap ").Cells(i, 9)
           GL.ListBox1.List(K, 6) = "| " & Sheets("Récap ").Cells(i, 8)
           GL.ListBox1.List(K, 7) = "| " & Sheets("Récap ").Cells(i, 30)
            DéBit = DéBit + Sheets("Récap ").Cells(i, 30)
           GL.ListBox1.List(K, 8) = "| " & Sheets("Récap ").Cells(i, 29)
            CréDit = CréDit + Sheets("Récap ").Cells(i, 29)
           GL.ListBox1.List(K, 9) = "| " & Sheets("Récap ").Cells(i, 4)
            K = K + 1
            'Sheets("feuil2").Range("c27") = i
     
        End If
        GL.ComptLigne = K
    Next i
    GL.TdéBit.Value = DéBit
    GL.TdéBit.Value = Format(GL.TCit.Value, "#,##0.00")
    GL.TcréDit.Value = CréDit
    GL.TcréDit.Value = Format(GL.TDit.Value, "#,##0.00")
    GL.TSolDe.Value = CréDit - DéBit
    GL.TSolDe.Value = Format(GL.TlDe.Value, "#,##0.00")
    GL.ProB1.Visible = False
    GL.Image1.Visible = False
    GL.ListBox1.ColumnWidths = "50;55;60;110;170;150;30;55;55;80"
     
    End Sub

    je n'ai pas regardé le reste du code en considerant qui fonctionne

    au plaisir
    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

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

Discussions similaires

  1. Réponses: 5
    Dernier message: 02/12/2014, 11h58
  2. Remplacer null par...
    Par HichamK dans le forum Oracle
    Réponses: 4
    Dernier message: 17/01/2006, 13h56
  3. Réponses: 2
    Dernier message: 14/11/2005, 13h33
  4. [Configuration] remplacement des é par des i
    Par illegalsene dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 2
    Dernier message: 18/10/2005, 16h37
  5. [ASP] include remplacer chemin par variable
    Par damn dans le forum ASP
    Réponses: 3
    Dernier message: 01/10/2004, 15h27

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