ผมได้เขียน code ตรวจสอบข้อมูล โดยรายละเอียดจะปรากฎในไฟล์แนบ ซึ่ง code ที่ผมเขียนขึ้นมามีดังนี้
code สำหรับใช้เมื่อกดปุ่ม ตรวจข้อมูล
Code: Select all
Sub check_data()
Range("b4").Select
Cells.Find(What:="*และ หักนอก", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.Offset(0, 2).Select
If Selection.Value = "" Then
MsgBox "กรอกจำนวนเงินที่ต้องการหักในช่องนี้"
Exit Sub
Else
Selection.Offset(0, -2).Select
Cells.Find(What:="*และ หักนอก", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.Offset(0, 2).Select
If Selection.Value <> "" Then
Exit Sub
End If
End If
End Sub
และ code สำหรับ worksheet ดังนี้
Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo errorline
If Target.Column = 4 Then
Selection.Offset(0, -2).Select
Cells.Find(What:="*และ หักนอก", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.Offset(0, 2).Select
If Selection.Value = "" Then
MsgBox "กรอกจำนวนเงินที่ต้องการหักในช่องนี้"
Else
Selection.Offset(0, -2).Select
Cells.Find(What:="*และ หักนอก", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.Offset(0, 2).Select
If Selection.Value <> "" Then
Range("a1").Select
MsgBox "ข้อมูลเรียบร้อย"
End If
End If
Exit Sub
Else
Exit Sub
End If
errorline:
Range("a1").Select
Exit Sub
End Sub
เพื่อให้งานออกมาสำเร็จตามที่ต้องการผมไม่แน่ใจว่าผมจะต้องเพิ่มเติม code หรือไม่ อย่างไร รบกวนขอคำแนะนำด้วยครับ

You do not have the required permissions to view the files attached to this post.