snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub CopyDataToDetailSheet()
Dim ws As Worksheet
Dim detailSheet As Worksheet
Dim lastCol As Long
Dim copyRange As Range
Set detailSheet = ThisWorkbook.Sheets("detail")
lastCol = 2
For Each ws In ThisWorkbook.Sheets
If ws.Name <> "data" And ws.Name <> "OP" And ws.Name <> "detail" Then
Set copyRange = ws.Range("A7:D30")
copyRange.Copy Destination:=detailSheet.Cells(3, lastCol)
lastCol = lastCol + copyRange.Columns.Count
End If
Next ws
MsgBox "การคัดลอกข้อมูลเสร็จสมบูรณ์"
End Sub
You do not have the required permissions to view the files attached to this post.
Sub CopyDataToDetailSheet()
Dim ws As Worksheet
Dim detailSheet As Worksheet
Dim lastCol As Long
Dim copyRange As Range
On Error Resume Next
Set detailSheet = ThisWorkbook.Sheets("detail")
lastCol = 2
For Each ws In ThisWorkbook.Sheets
If ws.Name <> "data" And ws.Name <> "OP" And ws.Name <> "detail" Then
Set copyRange = ws.Range("A7:D30")
lastCol = Application.Match(ws.Range("A5"), detailSheet.Range("b1:bu1"), 0)
copyRange.Copy Destination:=detailSheet.Cells(3, lastCol + 1)
lastCol = lastCol * 4
End If
Next ws
MsgBox "การคัดลอกข้อมูลเสร็จสมบูรณ์"
End Sub
Sub CopyDataToDetailSheet()
Dim ws As Worksheet
Dim detailSheet As Worksheet
Dim lastCol As Long
Dim copyRange As Range
On Error Resume Next
Set detailSheet = ThisWorkbook.Sheets("detail")
lastCol = 2
For Each ws In ThisWorkbook.Sheets
If ws.Name <> "data" And ws.Name <> "OP" And ws.Name <> "detail" Then
Set copyRange = ws.Range("A7:D30")
lastCol = Application.Match(ws.Range("A5"), detailSheet.Range("b1:bu1"), 0)
copyRange.Copy Destination:=detailSheet.Cells(3, lastCol + 1)
lastCol = lastCol * 4
End If
Next ws
MsgBox "การคัดลอกข้อมูลเสร็จสมบูรณ์"
End Sub