Code ด้านล่างนี้บันทึกข้อมูลไปที่ Sheet1 ไฟล์ PoBookShare ต้องการเพิ่ม Code ให้บันทึกได้ 2 ที่พร้อมกันโดยบันทึกไปที่ชีท Database ไฟล์ PO.Form ด้วยค่ะ
Code: Select all
Sub PasteData()
Dim wbShare As Workbook
Dim formBook As Workbook
Dim i As Integer
Dim rs As Range
Dim rt As Range
Set formBook = ThisWorkbook
Set wbShare = Workbooks("PoBookShare.xlsx")
Application.ScreenUpdating = False
With formBook
i = Worksheets("Enterthedata").Range("C225")
End With
With Worksheets("Template")
Set rs = .Range(.Range("A2"), .Range("AC" & i + 1))
End With
Set rt = wbShare.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
If Worksheets("Enterthedata").Range("C225") = True Then
MsgBox "Please check your data. This transaction already recorded."
Exit Sub
End If
If Worksheets("Enterthedata").Range("B204") = "" Then
MsgBox "Your data is empty. Fill your data and click record button again."
Exit Sub
End If
rs.Copy: rt.PasteSpecial xlPasteValues
Application.CutCopyMode = False
Sheets("Enterthedata").Range("D2,B204:B220,D204:D220,L204:L220,D222, E204:F220").ClearContents
With Worksheets("Enterthedata")
If Len(.Range("M2")) = 6 Then
.Range("M2") = Left(.Range("M2"), 2) & Right(.Range("M2"), 4) + 1
ElseIf Len(.Range("M2")) = 7 Then
.Range("M2") = Left(.Range("M2"), 1) & Right(.Range("M2"), 6) + 1
ElseIf Len(.Range("M2")) = 8 Then
.Range("M2") = Left(.Range("M2"), 1) & Right(.Range("M2"), 7) + 1
Else
.Range("M2") = .Range("M2") + 1
End If
End With
Application.ScreenUpdating = True
Windows("PO.Form.xlsm").Activate
ActiveWorkbook.Save
Windows("PoBookShare.xlsx").Activate
ActiveWorkbook.Save
End Sub
พอแทรก Code ด้านล่างนี้เข้าไป กลับบันทึกข้อมูลไปยังที่ชีท Database ไฟล์ PO.Form ได้ที่เดียวเท่านั้นค่ะ
ขอรบกวนช่วยปรับให้บันทีกได้ทั้งชีท Sheet1 ไฟล์ PoBookShare และ ชีท Database ไฟล์ PO.Form พร้อมกันทั้งสองที่ค่ะ
ขอบคุณค่ะ
Code: Select all
Set rt = Worksheets("Database").Range("A1048576").End(xlUp).Offset(1, 0)
If Worksheets("Enterthedata").Range("C225") = True Then
MsgBox "Please check your data. This transaction already recorded."
Exit Sub
End If