VBA : รวมข้อมูลหลายชีท
Posted: Tue Sep 29, 2020 4:09 pm
ต้องการดึงข้อมูล Recipe ที่อยู่ใน column B ของแต่ละชีทมาวาง ใน column B ของชีต DB โดยให้ขอบเขตข้อมูลตรงกันกับข้อมูลที่นำมาวางตามไฟล์แนบ รบกวนด้วยครับ
Code: Select all
Option Explicit
Sub CollectData()
Dim ws As Worksheet
Dim r As Range
Dim rTarget As Range
Dim ref
Application.ScreenUpdating = False
With Sheets("DB")
.UsedRange.ClearContents
.Range("A1:T1").Value = Array("WS", "Recipe", "Part Number", "Position", "FIDL", "Unit Name", "Class", "Pickup Count", "Total Parts Used", "Reject Parts", "No Pickup", "Error Parts", "Dislodged Parts", "Rescan Count", "LCR Check Used", "Pickup Rate", "Reject Rate", "Error Rate", "Dislodged Rate", "Success Rate")
End With
For Each ws In Worksheets
If ws.Name <> "DB" Then
With Sheets("DB")
Set rTarget = .Range("C" & Rows.Count).End(xlUp).Offset(1, 0)
ref = Sheets("DB").Range("C" & Rows.Count).End(xlUp).Row
End With
Set r = ws.Range("C14", ws.Range("T" & Rows.Count).End(xlUp).Offset(-1, 0))
r.Copy
rTarget.PasteSpecial xlPasteValues
Worksheets("DB").Range("A" & ref + 1, Range("B" & Rows.Count).End(xlUp).Offset(0, -1)) = ws.Name
End If
Next ws
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub