Page 1 of 1

การรวมข้อมูลแล้วให้แถบ Progress Bar แสดงผล

Posted: Wed Jan 11, 2012 12:34 pm
by niwat2811
สวัสดีครับท่านอาจารย์ ผมได้ลองทำแถบ Progress Bar เพื่อให้แสดงผลตอนรวมข้อมูล จาก Sheet1 มาไว้ที่ Sheet2 แต่ว่าแถบ Progress Bar ไม่ยอมแสดง ไม่ทราบว่า Code ผิดตรงไหนหรืออย่างไร รบกวนท่านอาจารย์โปรดชี้แนะด้วยครับ

Re: การรวมข้อมูลแล้วให้แถบ Progress Bar แสดงผล

Posted: Wed Jan 11, 2012 5:42 pm
by snasui
:D ลองปรับที่ UpdateData เป็นตามด้านล่างครับ

Code: Select all

Sub UpdateData()
    Dim rs As Range, rsAll As Range
    Dim rt As Range, rtAll As Range
    Dim PctDone As Single
    Dim Row As Long
    Dim Col As Long
    Dim iCount As Long
    UserForm1.Show vbModeless
    Application.ScreenUpdating = False
    With Sheets("Sheet1")
        Set rsAll = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
        Row = rsAll.Rows.Count
        Col = rsAll.Columns.Count
    End With
    With Sheets("Sheet2")
        Set rtAll = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
    End With
    For Each rt In rtAll
        For Each rs In rsAll
            If rs = rt Then
                rs.EntireRow.Copy
                rt.EntireRow.PasteSpecial xlPasteValues
                iCount = iCount + 1
            End If
        Next rs
        PctDone = iCount / (Row * Col)
        Call UpdateProgress(PctDone)
    Next rt
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    Unload UserForm1
End Sub