มีข้อสงสัยเรื่องทำ Template ค่ะ
หากจำไม่ผิดเคยอ่านโพสต์ของอาจารย์ ไฟล์ที่ใช้ VBA ควรทำชีท Template เพื่อจัดข้อมูลให้เป็นระเบียบ
เพราะการใช้ VBA อาจมีการ Copy ข้อมูลไปไว้หลายที่ หรือจะไม่มีชีท Template ก็ได้ ประมาณนี้ค่ะ
(
หรือหากจำผิดต้องขออภัยอาจารย์ค่ะ พยายามจะหาอ่านทวนก็จำไม่ได้อ่านจากกระทู้ไหนค่ะ)
ดังนั้นตัวอย่างไฟล์ของกระทู้นี้จึงขอลองทำแบบไม่มีชีท Template ค่ะ
bank9597 wrote:
น่าจะลองสร้างชีท Temp มาเพิ่มน่ะครับ เพื่อจัดระเบียบข้อมูล ทำให้แก้โค๊ดได้ง่ายและส้นกว่า
ลองดูที่ไฟล์แนบน่ะครับ
ต้องขอขอบคุณ คุณ bank9597 ค่ะ
ขอสงสัยคือหากทำชีท Template ควรทำ 1 Template ต่อ 1 ฐานข้อมูล หรือสามารถใช้ 1 Template ต่อ หลายฐานข้อมูล
ลองส่งไฟล์ต้วอย่างการทำชีท Template 2 แบบมาให้อาจารย์ช่วยแนะนำการออกแบบชีท Template ที่ดีควรจะเป็นแบบใดค่ะ
Code นี้ของชีท Template
Code: Select all
Sub PasteData()
Application.ScreenUpdating = False
Sheets("Template").Range("B2:K2").Copy
Sheets("Database").Range("A65536").End(xlUp).Offset(1, 0) _
.PasteSpecial xlPasteValues
Sheets("Template").Range("C2:D2").Copy
Sheets("Paid").Range("B" & Rows.Count).End(xlUp) _
.Offset(1, 0).PasteSpecial xlPasteValues
Sheets("Template").Range("G2").Copy
Sheets("Paid").Range("D" & Rows.Count).End(xlUp) _
.Offset(1, 0).PasteSpecial xlPasteValues
Sheets("Template").Range("I2").Copy
Sheets("Paid").Range("E" & Rows.Count).End(xlUp) _
.Offset(1, 0).PasteSpecial xlPasteValues
Sheets("Form").Range("C2,F2,H2:J2").ClearContents
With Sheets("Form")
.Range("B2") = .Range("B2") + 1
.Range("B3") = .Range("B3") + 1
End With
Sheets("Paid").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = _
Sheets("Form").Range("B3")
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Code นี้ของชีท Sheet2 แนบมากับไฟล์ตัวอย่างค่ะ
Code: Select all
Sub PasteData()
Application.ScreenUpdating = False
Sheets("Sheet2").Range("A2:J2").Copy
Sheets("Database").Range("A65536").End(xlUp).Offset(1, 0) _
.PasteSpecial xlPasteValues
Sheets("Sheet2").Range("K2:O2").Copy
Sheets("Paid").Range("A65536").End(xlUp).Offset(1, 0) _
.PasteSpecial xlPasteValues
Sheets("Form").Range("C2,F2,H2:J2").ClearContents
With Sheets("Form")
.Range("B2") = .Range("B2") + 1
.Range("B3") = .Range("B3") + 1
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
You do not have the required permissions to view the files attached to this post.