อาจารย์คะ รบกวนช่วยด้วยค่ะ วาง Code แบบด้านล่างนี้ก็ไม่ได้ค่ะ
Code: Select all
Sub BeenArL()
Dim rSource As Range
Dim rTarget As Range
Dim rs As Range ' ปุ่มบันทึกรับชำระ ชีท Form
Dim rt As Range
Dim i As Integer
With Sheets("Form")
Set rSource = .Range("B3:B47")
End With
With Sheets("Database")
Set rTarget = .Range("D2", .Range("D" & Rows.Count).End(xlUp))
End With
With ActiveSheet
i = (.Range("L4") + .Range("L6"))
If i <> .Range("J8") Then
MsgBox "โปรดตรวจจำนวนเงินและบันทึกใหม่"
Exit Sub
End If
End With
Application.Calculation = xlCalculationManual
For Each rs In rSource
For Each rt In rTarget
If rt = rs Then rt.Offset(0, 25) = "Y"
Next rt
Next rs
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False
Sheets("TemBilling").Range("A12:O12").Copy
Sheets("AR").Range("A" & Rows.Count).End(xlUp) _
.Offset(1, 0).PasteSpecial xlPasteValues
Sheets("TemBilling").Range("P12:W12").Copy
Sheets("Report").Range("A" & Rows.Count).End(xlUp) _
.Offset(1, 0).PasteSpecial xlPasteValues
Sheets("Form").Range("H1,J2,I4:L4,L6,G4").ClearContents
With Sheets("Form")
.Range("J6") = .Range("J6") + 1
End With
Application.ScreenUpdating = True
End Sub
ลองสับตำแหน่งการวางแบบด้านล่างนี้ก็ไม่ได้ทำไม่สำเร็จค่ะ
Code: Select all
Sub BeenArL()
Dim rSource As Range
Dim rTarget As Range
Dim rs As Range ' ปุ่มบันทึกรับชำระ ชีท Form
Dim rt As Range
Dim i As Integer
With Sheets("Form")
Set rSource = .Range("B3:B47")
End With
With Sheets("Database")
Set rTarget = .Range("D2", .Range("D" & Rows.Count).End(xlUp))
End With
Application.Calculation = xlCalculationManual
With ActiveSheet
i = (.Range("L4") + .Range("L6"))
If i <> .Range("J8") Then
MsgBox "โปรดตรวจจำนวนเงินและบันทึกใหม่"
Exit Sub
End If
End With
For Each rs In rSource
For Each rt In rTarget
If rt = rs Then rt.Offset(0, 25) = "Y"
Next rt
Next rs
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False
Sheets("TemBilling").Range("A12:O12").Copy
Sheets("AR").Range("A" & Rows.Count).End(xlUp) _
.Offset(1, 0).PasteSpecial xlPasteValues
Sheets("TemBilling").Range("P12:W12").Copy
Sheets("Report").Range("A" & Rows.Count).End(xlUp) _
.Offset(1, 0).PasteSpecial xlPasteValues
Sheets("Form").Range("H1,J2,I4:L4,L6,G4").ClearContents
With Sheets("Form")
.Range("J6") = .Range("J6") + 1
End With
Application.ScreenUpdating = True
End Sub