snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
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