Page 1 of 1

ขอความช่วยเหลือเรื่องใช้ Code Validation 2 ชุดใน 1 ชีท

Posted: Wed Dec 07, 2011 1:52 pm
by suka
เรียนอาจารย์ ขอความช่วยเหลือเรื่อง Code สำหรับใช้กับ Validation ต้องการใช้ 2 ตำแหน่งใน 1 ชีท
โดยเป็น Validation คนละชุดกันค่ะ ได้ทดลองใส่ Code ทั้ง 2 ชุดในชีทเดียวไม่ได้ค่ะ
ตัวอย่างโค๊ด 2 ชุดจะต้องปรับโค๊ดอย่างไรคะ

โค๊ดชุดที่ 1

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
On Error Resume Next
If Not Intersect(Target, Range("F2")) Is Nothing Then
    Worksheets("CustomerInformation").Range("P1") = Target
    Target.Select
    If Len(Target) < 3 Then
        Application.SendKeys "%{DOWN}"
    End If
End If
Application.EnableEvents = True
End Sub
ตัวอย่างโค๊ดอีกชุดค่ะ

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
On Error Resume Next
If Not Intersect(Target, Range("L2")) Is Nothing Then
    Worksheets("CustomerInformation").Range("F1") = Target
    Target.Select
    If Len(Target) < 3 Then
        Application.SendKeys "%{DOWN}"
    End If
End If
Application.EnableEvents = True
End Sub
ขอบคุณค่ะ

Re: ขอความช่วยเหลือเรื่องใช้ Code Validation 2 ชุดใน 1 ชีท

Posted: Wed Dec 07, 2011 2:23 pm
by bank9597
:lol: ลองปรับโค๊ดตามนี้ครับ

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
On Error Resume Next
If Not Intersect(Target, Range("F2")) Is Nothing Then
    Worksheets("CustomerInformation").Range("P1") = Target
    Target.Select
    If Len(Target) < 3 Then
        Application.SendKeys "%{DOWN}"
    End If
End If
If Not Intersect(Target, Range("L2")) Is Nothing Then
    Worksheets("CustomerInformation").Range("F1") = Target
    Target.Select
    If Len(Target) < 3 Then
        Application.SendKeys "%{DOWN}"
    End If
End If
Application.EnableEvents = True
End Sub