Como aplicar una ProgressBar mientras se ejecuta mi macro

Dante buen día, nuevamente apoyándome en ti para esta cuestión, ayer y antier me ayudaste con un ejemplo de Macro para mostrar columna oculta de acuerdo a fecha capturada en una celda ahora estoy viendo la forma de agregarle una ProgressBar a la macro, pero me he quedado a medias algo me falta, me puedes ayudar a revisarlo y ver que es lo que me hace falta.

Esto lo tengo en UserForm1

Private Sub FrameProgress_Click()
End Sub
Private Sub Label1_Click()
End Sub
Private Sub LabelProgress_Click()
End Sub
Private Sub UserForm_Activate()
    Call OcultarColumnas
End Sub

y esto lo tengo en el Modulo1

Sub ShowUserForm()
    UserForm1.Show
End Sub
Sub OcultarColumnas()
'Por.Dante Amor
    Dim Contador As Integer
    Dim Pct As Single
    Contador = 1
    ini = Columns("D").Column
    fin = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
    Range(Cells(1, ini), Cells(1, fin)).EntireColumn.Hidden = False
        Application.ScreenUpdating = False
    If [B3] <> "" Then
        For i = fin To ini Step -1
            If IsDate(Cells(1, i)) And Cells(1, i) <> [B3] Then
                Columns(i).EntireColumn.Hidden = True
                Contador = Contador + 1
            End If
    Pct = Contador / fin
         UpdateProgressBar Pct
        Next
    End If
    Unload UserForm1
End Sub
Sub UpdateProgressBar(Pct As Single)
    With UserForm1
        .FrameProgress.Caption = Format(Pct, "0%")
        .LabelProgress.Width = Pct * _
            (.FrameProgress.Width - 10)
    End With
     DoEvents
End Sub
              

1 respuesta

Respuesta
1

H o l a:

Prepara tu formulario de la siguiente forma:

1. Un frame llamado Frame1, con width = 306

2. Un label llamado Label1, con un width = 30

3. El Label1 debe estar dentro del Frame1.

4. Un Label llamado Label2, solamente para poner un mensaje.

5. Pon el código dentro del formulario:

Private Sub UserForm_Activate()
'Referencia: http://support.microsoft.com/kb/211736/es
'Mod.Por.Dante Amor
    Label1.Width = 0
    principal
End Sub
'
Sub principal()
'Por.Dante Amor
    Application.ScreenUpdating = False
    con = 1
    rep = 10
    Label2 = "Procesando ..."
    '
    ini = Columns("D").Column
    fin = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
    tot = fin - ini
    Range(Cells(1, ini), Cells(1, fin)).EntireColumn.Hidden = False
    If [B3] <> "" Then
        For i = fin To ini Step -1
            con = con + 1
            '
            If IsDate(Cells(1, i)) And Cells(1, i) <> [B3] Then
                Columns(i).EntireColumn.Hidden = True
            End If
            '
            If (con * 100) / tot >= rep Then
                UpdateProgressBar rep
                rep = rep + 10
            End If
        Next
    End If
    Application.ScreenUpdating = True
    Label2 = "Proceso Terminado"
End Sub
'
Sub UpdateProgressBar(ava)
'Por.Dante Amor
    UserForm1.Frame1.Caption = Int(ava) & " %"
    Label1.Width = Label1.Width + 30
    DoEvents
End Sub

El progreso de la barra avanzará de 10 en 10.

Si son pocas columnas, el efecto del progressbar no se apreciará.

La pregunta no admite más respuestas

Más respuestas relacionadas