+ Reply to Thread
Results 1 to 4 of 4

Progress bar

Hybrid View

  1. #1
    Registered User
    Join Date
    10-16-2009
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    31

    Progress bar

    Hello Gurus'
    Using Andy Popes' code / guidelines, I have the following excel macro which includes Progress bar code, but it doesnt work. The macro just does some calculations(which is working), but it takes long, so want to include the Progress bar, to let the user know that something is happening at the back.

    Attaching the file.....

    Need your help please...

    Thanks,
    Ravin
    Attached Files Attached Files

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,444

    Re: Progress bar help

    First move the routine out of the user form to a standard code module.

    Then remove the demonstration loop I used and place progress update within your existing loops.


    'THIS SUB RUNS THE "RUN PROGRESS METER" BUTTON
    Sub copyEquals()
    
    ' Progress Bar
        Dim frmProgress As UserForm1
        Dim lngIndex As Long
        Dim sngPercent As Single
        Dim lngMax As Long
        
        Dim Sht1Rng As Range, Sht2Rng As Range
        Dim Sht1Rng1 As Range, Sht2Rng1 As Range
        Dim OuterCell As Range, InnerCell As Range, Cell As Range, OuterCell2 As Range
        
        Set frmProgress = New UserForm1
        
        Set Sht1Rng = Range("Sht1") 'Named range for small table
        Set Sht1Rng1 = Range("Sht11") 'Named range for long table
        Set Sht2Rng = Range("Sht2") 'Named range for xfer of small table data
        Set Sht2Rng1 = Range("Sht21") 'Named range for xfer of long table data
            
        Application.Cursor = xlWait
        lngMax = Sht2Rng.Resize(, 1).Cells.Count + Sht2Rng1.Resize(, 1).Cells.Count
        sngPercent = lngIndex / lngMax
        frmProgress.ProgressStyle1 sngPercent, True
        frmProgress.Show vbModeless
        
        '------------------------
        ' Your code would go here
        
        For Each OuterCell In Sht2Rng.Resize(, 1)
            For Each InnerCell In Sht1Rng.Resize(, 1)
                'If OuterCell.Value = InnerCell.Value Then
                If InStr(1, OuterCell.Value, InnerCell.Value) Then
                    OuterCell.Offset(0, 1).Value = OuterCell.Offset(0, 1).Value + InnerCell.Offset(0, 1).Value
                End If
            Next
            lngIndex = lngIndex + 1
            sngPercent = lngIndex / lngMax
            frmProgress.ProgressStyle1 sngPercent, True
            DoEvents
        Next
        
        For Each OuterCell2 In Sht2Rng1.Resize(, 1)
            For Each Cell In Sht1Rng1.Resize(, 1)
                'If Right(OuterCell2.Value, ((Len(OuterCell2.Value) - 2) - _
                InStr(OuterCell2.Value, "By"))) = Cell.Value Then
                If InStr(1, OuterCell2.Value, Cell) Then
                    'MsgBox "OuterCell2.Value " & OuterCell2.Value
                    'MsgBox "Cell value " & cell.Value
                    OuterCell2.Offset(0, 1).Value = OuterCell2.Offset(0, 1).Value + Cell.Offset(0, 1).Value
                End If
            Next
            lngIndex = lngIndex + 1
            sngPercent = lngIndex / lngMax
            frmProgress.ProgressStyle1 sngPercent, True
            DoEvents
        Next
        
            
        Application.Cursor = xlDefault
        Unload frmProgress
        
    End Sub
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    10-16-2009
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    31

    Thumbs up Re: Progress bar help

    Hello Andy,
    You are a GEM of a person.....
    Bang on target.....So Can I go ahead and experiment with other graphics of your Progress Meters, by just replacing the "ProgressStyle1" name?

    Also, wanted your help, if you could help in the same excel.
    The macro is taking a unexpectedly long time for small job, which is just comparing two ranges, on 2 sheets and adding up some values.

    You can use the same excel....

    Thanks again,
    Ravin

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,444

    Re: Progress bar help

    Yes as long as you include all the relevant controls.

    But if you change you code so it only works with the data rather than the +100k cells in D:E then a progress bar is redundent

        Set Sht1Rng1 = Intersect(ActiveSheet.UsedRange, Range("Sht11")) 'Named range for long table

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1