สวัสดี ครับ อาจารย์
ผมขอรบกวน อาจารย์ หน่อยครับ
คือผมเป็นคนเก็บข้อมูลหลัก แล้วผมมีไฟล์ ให้น้องน้องป้อนข้อมูลรายชั่วโมงให้ แต่ด้วยความขี้เกี้ยดน้องน้องเลย copy อย่างเดียวทำให้ข้อมูลไม่มีการอัพเดดเปลี่ยนไปจากค่าเดีมเลย
ดั่งนั้น ผมจึ่งต้องทำไฟล์ที่มีเงื่อนไขแบบนี้เพื่อป้องกันความขี้เกียดครับ
เงื่อนไขก็คือ:
ถ้าหากผมป้อนเวลาลงใน cell "B2" และข้อมูลลงใน cell "C2:D2,C5:D5" ของ sheet"Input page"
แล้วเมื่อกดปุ่ม Save แล้วให้มันตรวจสอบเงื่อนไขว่า
ค่าใน cell "B2" ของ sheet"Input page" เท่ากับ ค่าใดใน cell "B2:B25" ของ sheet"Story information page 1" และ sheet"Story information page 2"
ให้ copy cell"C2:D2" ของ sheet"Input page" ไปไว้ใน cell "C2:D25" ของ sheet"Story information page 1"
ตามค่าของ cell "B2:B25" ของ sheet"Input page"
และ ให้ copy cell"C5:D5" ของ sheet"Input page" ไปไว้ใน cell "C2:D25" ของ sheet"Story information page 2"
ตามค่าของ cell "B2:B25" ของ sheet"Input page"
แล้วเมือเราป้อนเข้าไปในเวลาใหม่ก็ให้มัน save ไปตามเวลาที่ได้วางเอาไว้ ครับ
แต่ผมพึงเขียนได้นิดเดียวเพื่อทดสอบดูก่อนแต่มันก็ไม่ work ให้ผมเลยครับ มันจะโดดไปหา เงื่อนไขของ Else เลย
ขอรบกวน อาจารย์ ด้วยครับ
Code: Select all
Private Sub CommandButton1_Click()
ThisWorkbook.Worksheets("Storage information page 1").Unprotect Password:="1"
ThisWorkbook.Worksheets("Storage information page 2").Unprotect Password:="1"
If Worksheets("Input page").Range("B2").Value = "00:00" Then
Worksheets("Input page").Range("C2:D2").Select
Application.CutCopyMode = False
Selection.Copy
Worksheets("Storage information page 1").Range("C2:D2").Select
Selection.PasteSpecial Paste:=xlPasteValues
Else
Worksheets("Storage information page 1").Range("C2:D2").Value = 0
MsgBox ("Incomplete information, Please check and save again...")
End If
ThisWorkbook.Worksheets("Input page").Range("B2:D2").ClearContents
ThisWorkbook.Worksheets("Input page").Range("C5:D5").ClearContents
ThisWorkbook.Worksheets("Storage information page 1").Protect Password:="1"
ThisWorkbook.Worksheets("Storage information page 2").Protect Password:="1"
ActiveWorkbook.Save
End Sub