+ Reply to Thread
Results 1 to 28 of 28

How to place and define progress bar with percentage

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    How to place and define progress bar with percentage

    Hi,

    My VBA code will copy and paste several workbooks into master list.

    the cells to be pasted will be starting on cells(13,9) until cells(13,501) or Range("I13:SG13")

    while the max row will be determined by Cells(Rows.Count, "F").End(xlUp).Row


    Here is the progress bar code I found in internet, maxrow/column has been changed to my requirement but how to place my VBA code to this script? the one highlighted in red, I guess it

    Sub ShowProgressInStatus()
        Dim Percent As Integer
        Dim PercentComplete As Single
        Dim MaxRow, MaxCol As Integer
        MaxRow = Cells(Rows.Count, "F").End(xlUp).Row
        MaxCol = 501
        Percent = 0
        For irow = 13 To MaxRow
            For icol = 9 To MaxCol
                    
                 Worksheets("Sheet1").Cells(irow, icol).Value = irow
            Next
            PercentComplete = irow * icol / (MaxRow * MaxCol)
            Application.StatusBar = Format(PercentComplete, "0%") & " Completed"
            DoEvents
        Next
        Application.StatusBar = ""
    End Sub
    Last edited by Faridwahidi; 05-26-2014 at 06:46 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi,

    Can anyone help me to create VBA code for percentage of completion as above to my VBA code below.

    Sub SeachName_ArraySet()
    Dim lngRet As Long, lngCount As Long, lngVar As Long
    Dim var As Variant, varSheets As Variant, varBooks As Variant
    Dim a1 As Integer, a2 As Integer, bk As Integer
    Dim wb As Workbook, ws As Worksheet
    
    
    var = Array("Azizah Yusoff", "Hoo Zhe Yee", "Ong Xie Jun", "Gregory Gan Chong Hee", "Ong Pui Sin")
    varSheets = Array("Azizah", "Zhe Yee", "Xie Jun", "Gregory Gan", "Ong Pui")
    varBooks = Array("BUSINESS BANKING.xlsx", "Auto Finance.xlsx", "Small Medium Enterprise.xlsx")
    
    
        For bk = LBound(varBooks) To UBound(varBooks)
        
            Set wb = Workbooks(varBooks(bk))
            
            For lngVar = LBound(var) To UBound(var)
                    For Each ws In wb.Worksheets
                        If ws.Name = CStr(varSheets(lngVar)) Then GoTo Matchup
                    Next: GoTo GetNext
                    
    Matchup:
    lngRet = MatchName(ThisWorkbook.Name, "SOP BUSINESS UNIT - ORIGINATOR", CStr(var(lngVar)), 6)
          
                    If lngRet <> 0 Then
                          For lngCount = 0 To 11
    
                             
                              'Pasting Code No.1
                              ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 3 + lngCount).Value = _
                                  wb.Worksheets(CStr(varSheets(lngVar))).Range("H601").Offset(0, lngCount * 3).Value
    
                              'Pasting Code No.2
                              '
                              '
                              '
                              'Pasting Code No.9
                          Next lngCount
                          
                              'Pasting Code No.10
                              
                              ''''''''''''''''''update the progress bar for percentage of completion here'''''''''''''''''''''
                    End If
              
    GetNext:     Next lngVar
        
            Set wb = Nothing
        Next bk
    End Sub

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to place and define progress bar with percentage

    Can you please refer this code and see whether it helps you?

    Sub ToCheckVariableStringHoldingLimit()
    Dim i As Integer, s As String, blStatus As Boolean
    
    With Application
        blStatus = .DisplayStatusBar
        .DisplayStatusBar = True
        
        For i = 1 To 5000
            s = s & Application.Rept("A", 5 ^ 5)
            .StatusBar = i & " of 5000 " & "(" & Format(i / 5000, "00.00%") & ") Completed"
        Next i
        
        MsgBox Len(s)
        .StatusBar = False
        .DisplayStatusBar = blStatus
    End With
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi sixthsense,

    This code will make my VBA code running slowly, to many cells it runs (5000).

    What I want is percentage bar will be updated after completing one row, i.e. cells(13,9) until cells(13,501)

    If the cells move to the next row, cells(14,9), percentage bar will be automatically updated. max row is determined by Cells(Rows.Count, "F").End(xlUp).Row

    e.g.
    a = Cells(Rows.Count, "F").End(xlUp).Row

    Thus range of rows is Range("F13" & a).select


    Regards,
    Farid

  5. #5
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to place and define progress bar with percentage

    Quote Originally Posted by Faridwahidi View Post
    This code will make my VBA code running slowly, to many cells it runs (5000)
    I just given that code to show how it can be written and don't take that code to your present scenario just wanted to show the method about how to achieve it.

    Ok.. I will look into your code and add that logic in your code and post it here...

  6. #6
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi Sixthsense,

    Thanks for spend your time to assist me.

  7. #7
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to place and define progress bar with percentage

    Try this... Code provided based on your Post #1 code

    Sub ShowProgressInStatus()
        Dim PercentComplete As Single
        Dim MaxRow As Long, lRow As Long, lTot As Long, lCounter As Long
        Dim MaxCol As Integer, iCol As Integer
        Dim StartCol As Integer, StartRow As Long
        
        MaxRow = Cells(Rows.Count, "F").End(xlUp).Row
        MaxCol = 501
        StartRow = 13: StartCol = 9
        lTot = Range(Cells(StartRow, StartCol), Cells(MaxRow, MaxCol)).Cells.Count
        
        For lRow = StartRow To MaxRow
            For iCol = StartCol To MaxCol
                Worksheets("Sheet1").Cells(lRow, iCol).Value = lRow
                lCounter = lCounter + 1
                PercentComplete = lCounter / lTot
                Application.StatusBar = Format(PercentComplete, "0%") & " Completed"
            Next
            DoEvents
        Next
        
        Application.StatusBar = ""
        MsgBox "Job Done", vbInformation, "Task Completed"
    End Sub

  8. #8
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi sixthsense,

    There is misunderstood. I dont want percentage running by pasting value to the cell. It will return error while percentage runs until ???% and showed 3 times of message box at 100%, 200%, 300% and until 312% I have press Esc button to stop it.

    Worksheets("Sheet1").Cells(lRow, iCol).Value = lRow
    You dont need to exactly follow Post #1 as I am not sure which is the accurate code.


    My VBA code is as follow:
    Open another files to copy and paste value start on row 13 until Cells(Rows.Count, "F").End(xlUp).Row. Just update the percentage of completion everytime when ActiveCell.row moved from 13 to 14, and 14 moved 15, and so on.


    To make you clear understand on my pasting code. Here is the description

    start on cells(13,9) until cells(13,501)
    moved to cells(14,9) until cells(14,501) update % completion
    moved to cells(15,9) until cells(15,501) update % completion
    '
    ' '
    ' '
    ' '
    '

    until moved to cells(a,9) until cells(a,501) 100% completed

    while a = Cells(Rows.Count, "F").End(xlUp).Row



    Regards,
    Farid
    Last edited by Faridwahidi; 05-27-2014 at 06:12 AM.

  9. #9
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to place and define progress bar with percentage

    This is my level best code...

    Sub ShowProgressInStatus()
        Dim PercentComplete As Single, SubPercent As Single
        Dim MaxRow As Long, lRow As Long, lTot As Long
        Dim lCounter As Long, lIncre As Long, lSubTot As Long
        Dim MaxCol As Integer, iCol As Integer
        Dim StartCol As Integer, StartRow As Long
        
        
        MaxRow = Cells(Rows.Count, "F").End(xlUp).Row
        MaxCol = 501
        StartRow = 13: StartCol = 9
        lTot = Range(Cells(StartRow, StartCol), Cells(MaxRow, MaxCol)).Rows.Count
        lSubTot = MaxCol - StartCol
        For lRow = StartRow To MaxRow
            For iCol = StartCol To MaxCol
                Worksheets("Sheet1").Cells(lRow, iCol).Value = lRow
                lIncre = lIncre + 1
                SubPercent = lIncre / lSubTot
                Application.StatusBar = Format(PercentComplete, "0%") & " Completed " & Format(SubPercent, "(0%)") & " In Progress"
            Next
            lCounter = lCounter + 1
            PercentComplete = lCounter / lTot
            Application.StatusBar = Format(PercentComplete, "0%") & " Completed"
            DoEvents
            lIncre = 0
        Next
        
        Application.StatusBar = ""
    End Sub

  10. #10
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi sixthsense,

    Your VBA code look better than before (nice Code), but still running out of limit, more than 100%.

    I only change the sheet name and the rest remained the same.

    Worksheets("Sheet1").Cells(lRow, iCol).Value = lRow


    I attached the sample of small range workbooks consist of 5 persons . In fact, I have 200 persons to be updated. The estimated time is around 8-10 mins depending of Desktop processor.

    The VBA code is in Consolidation SOP workbooks.

    Thanks for your effort, I'm really appreciate
    Attached Files Attached Files

  11. #11
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to place and define progress bar with percentage

    Can you please show the code which goes beyond 100%.

    Because in your attached file I don't see any code which shows the progress

  12. #12
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi sixthsense,

    I have tried on this, but it runs out of limit & paste value to the cells. it should only count the completed cells.

  13. #13
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi Sixth sense,

    There is no VBA code for the progress bar you have created in my attachment. I have tried and error to place your progress bar code in the inner loop.

    The error as follow;
    It runs out of limit (>100%).
    The progress bar code have pasted value to the cell. overwritte my pasting code. It shoud only count the non-empty sell. NOT pasting value to the cell.

    can you please open all attachment, find VBA code in workbooks ( Consolidation SOP 2014.xlsm).

    Sub SeachName_ArraySet_A()
    Dim lngRet As Long, lngCount As Long, lngVar As Long
    Dim var As Variant, varSheets As Variant, varBooks As Variant
    Dim a1 As Integer, a2 As Integer, bk As Integer
    Dim wb As Workbook, ws As Worksheet
    
    var = Array("Azizah Yusoff", "Hoo Zhe Yee", "Ong Xie Jun", "Gregory Gan Chong Hee", "Ong Pui Sin")
    varSheets = Array("Azizah", "Zhe Yee", "Xie Jun", "Gregory Gan", "Ong Pui")
    varBooks = Array("BUSINESS BANKING.xlsx", "Auto Finance.xlsx", "Small Medium Enterprise.xlsx")
    
        For bk = LBound(varBooks) To UBound(varBooks)
        
            Set wb = Workbooks(varBooks(bk))
        
                For lngVar = LBound(var) To UBound(var)
                    For Each ws In wb.Worksheets
                    If ws.Name = CStr(varSheets(lngVar)) Then GoTo Matchup
                    Next: GoTo GetNext
    Matchup:
    lngRet = MatchName(ThisWorkbook.Name, "SOP BUSINESS UNIT - ORIGINATOR", CStr(var(lngVar)), 6)
              
              
              If lngRet <> 0 Then
                        For lngCount = 0 To 11
                        
                        'No.1
                            ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 3 + lngCount).Value = _
                                wb.Worksheets(CStr(varSheets(lngVar))).Range("H601").Offset(0, lngCount * 3).Value
                        
                        'No.2
                            ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 15 + lngCount * 3).Value = _
                                wb.Worksheets(CStr(varSheets(lngVar))).Range("H606").Offset(0, lngCount * 3).Value
                        'No.3
                        'No.4
                        'No.5
                        'No.6
                        'No.7
                        'No.8
                        'No.9
                
                        Next lngCount
                    
                        'No.10
                            ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 494).Value = _
                                wb.Worksheets(CStr(varSheets(lngVar))).Range("P612").Value
                
                            ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 495).Value = _
                                wb.Worksheets(CStr(varSheets(lngVar))).Range("P614").Value
    
                        
                        '''''''''''''''''''''''''''''Maybe the percentage of progress bar update here''''''''''''''''''''''''''''''''
                        
                                Dim PercentComplete As Single, SubPercent As Single
                                Dim MaxRow As Long, lRow As Long, lTot As Long
                                Dim lCounter As Long, lIncre As Long, lSubTot As Long
                                Dim MaxCol As Integer, iCol As Integer
                                Dim StartCol As Integer, StartRow As Long
                                
                                MaxRow = Cells(Rows.Count, "F").End(xlUp).Row
                                MaxCol = 501
                                StartRow = 13: StartCol = 9
                                lTot = Range(Cells(StartRow, StartCol), Cells(MaxRow, MaxCol)).Rows.Count
                                lSubTot = MaxCol - StartCol
                                For lRow = StartRow To MaxRow
                                    For iCol = StartCol To MaxCol
                                        Worksheets("SOP BUSINESS UNIT - ORIGINATOR").Cells(lRow, iCol).Value = lRow
                                        lIncre = lIncre + 1
                                        SubPercent = lIncre / lSubTot
                                        Application.StatusBar = Format(PercentComplete, "0%") & " Completed " & Format(SubPercent, "(0%)") & " In Progress"
                                    Next
                                    lCounter = lCounter + 1
                                    PercentComplete = lCounter / lTot
                                    Application.StatusBar = Format(PercentComplete, "0%") & " Completed"
                                    DoEvents
                                    lIncre = 0
                                Next
                                
                                Application.StatusBar = ""
    
                    End If
                
    GetNext:   Next lngVar
        
            Set wb = Nothing
        Next bk
    End Sub
    Last edited by Faridwahidi; 05-28-2014 at 01:55 AM.

  14. #14
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to place and define progress bar with percentage

    Sorry I don't have that much of time to check your code and apply the progression.

    Please apply the given logic since it is going to be a simple arithmetical calculation like dividing the count based on the number of loops.

  15. #15
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi sixthsense,

    when I press Esc button to cancel, Debug error stop at lCounter = lCounter + 1

  16. #16
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to place and define progress bar with percentage

    Quote Originally Posted by Faridwahidi View Post
    when I press Esc button to cancel, Debug error stop at lCounter = lCounter + 1
    Because at the time of pressing Esc the code was interrupted at that line because of pressing ESC.

  17. #17
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi sixthsense,

    The Esc button press when it runs out of limit (>100%).

    and your progress bar code should not paste value to the cells. It should only count the cells.

  18. #18
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi sixthsense,

    I have created a simple VBA code. How to place progress bar.

    The progress bar code should not paste value to the cells, but only count the completed cells.


    Sub copyPaste()
    
    Range("A1").Copy
            
        For i = 0 To 500
        Cells(13, 9).Offset(i, 0).Select
        ActiveSheet.Paste 'update progress bar after pasting, before move to the next row
        Next i
    
    Application.CutCopyMode = False
    End Sub
    Last edited by Faridwahidi; 05-28-2014 at 05:35 AM.

  19. #19
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to place and define progress bar with percentage

    I'm not 100% sure but looking at your code here:
    Sub SeachName_ArraySet_A()
    Dim lngRet As Long, lngCount As Long, lngVar As Long
    Dim var As Variant, varSheets As Variant, varBooks As Variant
    Dim a1 As Integer, a2 As Integer, bk As Integer
    Dim wb As Workbook, ws As Worksheet
    
    var = Array("Azizah Yusoff", "Hoo Zhe Yee", "Ong Xie Jun", "Gregory Gan Chong Hee", "Ong Pui Sin")
    varSheets = Array("Azizah", "Zhe Yee", "Xie Jun", "Gregory Gan", "Ong Pui")
    varBooks = Array("BUSINESS BANKING.xlsx", "Auto Finance.xlsx", "Small Medium Enterprise.xlsx")
    
        For bk = LBound(varBooks) To UBound(varBooks)
        
            Set wb = Workbooks(varBooks(bk))
        
                For lngVar = LBound(var) To UBound(var)
                    For Each ws In wb.Worksheets
                    If ws.Name = CStr(varSheets(lngVar)) Then GoTo Matchup
                    Next: GoTo GetNext
    Matchup:
    lngRet = MatchName(ThisWorkbook.Name, "SOP BUSINESS UNIT - ORIGINATOR", CStr(var(lngVar)), 6)
              
              
              If lngRet <> 0 Then
                        For lngCount = 0 To 11
                        
                        'No.1
                            ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 3 + lngCount).Value = _
                                wb.Worksheets(CStr(varSheets(lngVar))).Range("H601").Offset(0, lngCount * 3).Value
                        
                        'No.2
                            ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 15 + lngCount * 3).Value = _
                                wb.Worksheets(CStr(varSheets(lngVar))).Range("H606").Offset(0, lngCount * 3).Value
                        'No.3
                        'No.4
                        'No.5
                        'No.6
                        'No.7
                        'No.8
                        'No.9
                
                        Next lngCount
                    
                        'No.10
                            ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 494).Value = _
                                wb.Worksheets(CStr(varSheets(lngVar))).Range("P612").Value
                
                            ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 495).Value = _
                                wb.Worksheets(CStr(varSheets(lngVar))).Range("P614").Value
    
                        
                        '''''''''''''''''''''''''''''Maybe the percentage of progress bar update here''''''''''''''''''''''''''''''''
                        
                                Dim PercentComplete As Single, SubPercent As Single
                                Dim MaxRow As Long, lRow As Long, lTot As Long
                                Dim lCounter As Long, lIncre As Long, lSubTot As Long
                                Dim MaxCol As Integer, iCol As Integer
                                Dim StartCol As Integer, StartRow As Long
                                
                                MaxRow = Cells(Rows.Count, "F").End(xlUp).Row
                                MaxCol = 501
                                StartRow = 13: StartCol = 9
                                lTot = Range(Cells(StartRow, StartCol), Cells(MaxRow, MaxCol)).Rows.Count
                                lSubTot = MaxCol - StartCol
                                For lRow = StartRow To MaxRow
                                    For iCol = StartCol To MaxCol
                                        Worksheets("SOP BUSINESS UNIT - ORIGINATOR").Cells(lRow, iCol).Value = lRow
                                        lIncre = lIncre + 1
                                        SubPercent = lIncre / lSubTot
                                        Application.StatusBar = Format(PercentComplete, "0%") & " Completed " & Format(SubPercent, "(0%)") & " In Progress"
                                    Next
                                    lCounter = lCounter + 1
                                    PercentComplete = lCounter / lTot
                                    Application.StatusBar = Format(PercentComplete, "0%") & " Completed"
                                    DoEvents
                                    lIncre = 0
                                Next
                                
                                Application.StatusBar = ""
    
                    End If
                
    GetNext:   Next lngVar
        
            Set wb = Nothing
        Next bk
    End Sub
    I think the problem could be that you are looping through the "progress bar" bit several times as part of the For lngVar = LBound(var) To UBound(var) but I don't think you reset the lCounter that you base your progress bar on, so for the 2nd, 3rd, 4th times etc, it will be going from whatever the previous lCounter value was. So maybe try adding, Lcounter = 0 before the for lrow = startrow to maxrow bit, e.g.:
    Sub SeachName_ArraySet_A()
    Dim lngRet As Long, lngCount As Long, lngVar As Long
    Dim var As Variant, varSheets As Variant, varBooks As Variant
    Dim a1 As Integer, a2 As Integer, bk As Integer
    Dim wb As Workbook, ws As Worksheet
    
    var = Array("Azizah Yusoff", "Hoo Zhe Yee", "Ong Xie Jun", "Gregory Gan Chong Hee", "Ong Pui Sin")
    varSheets = Array("Azizah", "Zhe Yee", "Xie Jun", "Gregory Gan", "Ong Pui")
    varBooks = Array("BUSINESS BANKING.xlsx", "Auto Finance.xlsx", "Small Medium Enterprise.xlsx")
    
        For bk = LBound(varBooks) To UBound(varBooks)
        
            Set wb = Workbooks(varBooks(bk))
        
                For lngVar = LBound(var) To UBound(var)
                    For Each ws In wb.Worksheets
                    If ws.Name = CStr(varSheets(lngVar)) Then GoTo Matchup
                    Next: GoTo GetNext
    Matchup:
    lngRet = MatchName(ThisWorkbook.Name, "SOP BUSINESS UNIT - ORIGINATOR", CStr(var(lngVar)), 6)
              
              
              If lngRet <> 0 Then
                        For lngCount = 0 To 11
                        
                        'No.1
                            ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 3 + lngCount).Value = _
                                wb.Worksheets(CStr(varSheets(lngVar))).Range("H601").Offset(0, lngCount * 3).Value
                        
                        'No.2
                            ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 15 + lngCount * 3).Value = _
                                wb.Worksheets(CStr(varSheets(lngVar))).Range("H606").Offset(0, lngCount * 3).Value
                        'No.3
                        'No.4
                        'No.5
                        'No.6
                        'No.7
                        'No.8
                        'No.9
                
                        Next lngCount
                    
                        'No.10
                            ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 494).Value = _
                                wb.Worksheets(CStr(varSheets(lngVar))).Range("P612").Value
                
                            ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 495).Value = _
                                wb.Worksheets(CStr(varSheets(lngVar))).Range("P614").Value
    
                        
                        '''''''''''''''''''''''''''''Maybe the percentage of progress bar update here''''''''''''''''''''''''''''''''
                        
                                Dim PercentComplete As Single, SubPercent As Single
                                Dim MaxRow As Long, lRow As Long, lTot As Long
                                Dim lCounter As Long, lIncre As Long, lSubTot As Long
                                Dim MaxCol As Integer, iCol As Integer
                                Dim StartCol As Integer, StartRow As Long
                                lCounter = 0
                                MaxRow = Cells(Rows.Count, "F").End(xlUp).Row
                                MaxCol = 501
                                StartRow = 13: StartCol = 9
                                lTot = Range(Cells(StartRow, StartCol), Cells(MaxRow, MaxCol)).Rows.Count
                                lSubTot = MaxCol - StartCol
                                For lRow = StartRow To MaxRow
                                    For iCol = StartCol To MaxCol
                                        Worksheets("SOP BUSINESS UNIT - ORIGINATOR").Cells(lRow, iCol).Value = lRow
                                        lIncre = lIncre + 1
                                        SubPercent = lIncre / lSubTot
                                        Application.StatusBar = Format(PercentComplete, "0%") & " Completed " & Format(SubPercent, "(0%)") & " In Progress"
                                    Next
                                    lCounter = lCounter + 1
                                    PercentComplete = lCounter / lTot
                                    Application.StatusBar = Format(PercentComplete, "0%") & " Completed"
                                    DoEvents
                                    lIncre = 0
                                Next
                                
                                Application.StatusBar = ""
    
                    End If
                
    GetNext:   Next lngVar
        
            Set wb = Nothing
        Next bk
    End Sub

  20. #20
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi raguldy,

    Thanks for willing to assist me. With Lcounter = 0, after reach 100%, the percentage back to 0% and it runs again.


    Another problem is the progress bar code have pasted value to the cells while running to calculate percentage. So, my pasting code have been overwritten, When i check the output, it show number 13 ---501.

    This is the code.
     Worksheets("SOP BUSINESS UNIT - ORIGINATOR").Cells(lRow, iCol).Value = lRow
    I try to change it to count, but it does not work.
     Worksheets("SOP BUSINESS UNIT - ORIGINATOR").Cells(lRow, iCol).Count = lRow
    I think, it is enough to update the percentage completion after macro have completed pasting value to one row. e.g. cells(13,9) to cells(13,501). before activeCell moved to the next cells(14,9) until cells(14,501) and so on until maxrow= Cells(Rows.Count, "F").End(xlUp).Row

    Please help me, thanks a lot.
    Last edited by Faridwahidi; 05-28-2014 at 08:58 AM.

  21. #21
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to place and define progress bar with percentage

    Ok, I see, try:
    Sub SeachName_ArraySet_A()
    Dim lngRet As Long, lngCount As Long, lngVar As Long
    Dim var As Variant, varSheets As Variant, varBooks As Variant
    Dim a1 As Integer, a2 As Integer, bk As Integer
    Dim wb As Workbook, ws As Worksheet
    var = Array("Azizah Yusoff", "Hoo Zhe Yee", "Ong Xie Jun", "Gregory Gan Chong Hee", "Ong Pui Sin")
    varSheets = Array("Azizah", "Zhe Yee", "Xie Jun", "Gregory Gan", "Ong Pui")
    varBooks = Array("BUSINESS BANKING.xlsx", "Auto Finance.xlsx", "Small Medium Enterprise.xlsx")
    For bk = LBound(varBooks) To UBound(varBooks)
        Set wb = Workbooks(varBooks(bk))
        For lngVar = LBound(var) To UBound(var)
            Set ws = Nothing
            On Error Resume Next
            Set ws = wb.Sheets(varSheets(lngVar))
            On Error GoTo 0
            If Not ws Is Nothing Then
                lngRet = MatchName(ThisWorkbook.Name, "SOP BUSINESS UNIT - ORIGINATOR", CStr(var(lngVar)), 6)
                If lngRet <> 0 Then
                    For lngCount = 0 To 11
                        ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 3 + lngCount).Value = _
                            wb.Worksheets(CStr(varSheets(lngVar))).Range("H601").Offset(0, lngCount * 3).Value
                        ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 15 + lngCount * 3).Value = _
                            wb.Worksheets(CStr(varSheets(lngVar))).Range("H606").Offset(0, lngCount * 3).Value
                    Next lngCount
                    ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 494).Value = _
                        wb.Worksheets(CStr(varSheets(lngVar))).Range("P612").Value
                    ThisWorkbook.Sheets("SOP BUSINESS UNIT - ORIGINATOR").Range("F" & lngRet).Offset(0, 495).Value = _
                        wb.Worksheets(CStr(varSheets(lngVar))).Range("P614").Value
                End If
            End If
            Application.StatusBar = Format((bk * (UBound(var) + 1) + lngVar + 1) / ((UBound(varBooks) + 1) * (UBound(var) + 1)), "0%")
        Next lngVar
        Set wb = Nothing
    Next bk
    Application.StatusBar = False
    End Sub

  22. #22
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi ragulduy,

    Unbelievable, it works . Thousands appreciation to you. , I have added reputation to you.


    But the percentage jump from 18% to 49% and 55% to 89% . I guess, it could be due to one of the files completed pasting value.

  23. #23
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to place and define progress bar with percentage

    I think that the percentage should go up in equal steps, but it will appear to skip some because if it doesn't find the worksheet it will move to the next counter and so will update quicker than you will be able to see. So the progress bar is based on the counter, not the number of sheets to open.

  24. #24
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi ragulduy,

    Thanks for the information.

    However, i think excel can only give estimation % but cannot give accurate %.

    To make it easy to check, I have created simple code and run a single step using F8 button.

    Sub copyPaste()
    Dim i As Long
    Dim PercentComplete As Variant
    
    Range("A1").Copy
            
        For i = 1 To 5000
        Cells(1, 3).Offset(i, 0).Select
        ActiveSheet.Paste
        PercentComplete = i / 5000
        Application.StatusBar = Format(PercentComplete, "0%") & " Completed"
        Next i
    
    Application.CutCopyMode = False
    End Sub
    Excel display:
    1% at row 25, should be at row 50
    2% at row 76, should be at row 100
    3% at row 128, should be at row 150

  25. #25
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to place and define progress bar with percentage

    That's because you are rounding it to the nearest percent.

    so row 128 = 128/5000 = 2.56% which is rounded to 3%.

    Either change format(percentcomplete,"0%") to format(percentcomplete,"0.0%") or if you only want it to display 3% once 3% has been reached rather than rounding up then:
    percentcomplete = worksheetfunction.rounddown(i/5000,2)

  26. #26
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi ragulduy,

    Thanks a lot. I have gained my knowledge.

    Just to get confirmation, Is it possible to display time left?

    If yes, I will ask in a new thread.

  27. #27
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to place and define progress bar with percentage

    I suppose you could come up with a very rough estimate but it would be pretty much redundant.

    I would suggest time a bunch of them and see how long they take, calculate the average of these times, divide this average by 100 to get the time for each percent and then use this to calculate how long is left (i.e. time taken per percent * number of percent remaining)

  28. #28
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: How to place and define progress bar with percentage

    Hi ragulduy,

    Here is the link for a new thread. To make it easy to understand, I only use simple code same as post #24.

    I just want to get a basic learning, and clearly understand before go to complicated script.


    http://www.excelforum.com/excel-prog...ml#post3712532

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Progress percentage function for student's grades
    By ckonsta in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-20-2013, 02:17 AM
  2. Progress bar or indicator to display calculation percentage
    By Dan27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2013, 01:13 PM
  3. [SOLVED] Format Percentage to 1 Decimal Place
    By Gos-C in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-09-2013, 08:01 PM
  4. percentage progress bar in vba
    By djwaz69 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-17-2013, 10:34 PM
  5. Replies: 1
    Last Post: 10-05-2007, 10:14 PM

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