Page 1 of 1

Search ออก เเต่ปัญหาติดว่าไม่ออกค่าล่าสุด

Posted: Wed Jul 18, 2018 3:17 pm
by BooBee
รบกวนผู้รู้ดู โค้ดให้หน่อยค่ะ

เนื่องจาก พอเวลา กด ปุ่ม Search เเล้วอยากได้ค่า ที่ออกมาล่าสุด เเต่โค้ดอันนี้ค่าที่แอดไปตอนเเรกมาเเสดงคะ

Code: Select all

Sub search_data()
 Range("B15:K18").Select
Selection.ClearContents
s_data = ([C11].Value)
If (s_data = "") Then
Range("C11").Select
MsgBox "ãÊèàÅ¢ Serial No"
Else

r1 = 15

Sheets("Database").Select
ActiveSheet.Range("E:E").End(xlDown).Select

'Sheets("Database").Select
'Range("E:E").Select
'Selection.End(xlDown).Select

Rrow = Selection.Row
    For x = 2 To Rrow
    
        a1 = Cells(x, 1).Value
        a2 = Cells(x, 2).Value
        a3 = Cells(x, 3).Value
        a4 = Cells(x, 4).Value
        a5 = Cells(x, 5).Value
        a6 = Cells(x, 6).Value
        a7 = Cells(x, 7).Value
        a8 = Cells(x, 8).Value
        a9 = Cells(x, 9).Value
        a10 = Cells(x, 10).Value
        
            If (s_data = a5) Then
            Sheets("Add").Select
               
                Cells(r1, "b").Value = a1
                Cells(r1, "c").Value = a2
                Cells(r1, "d").Value = a3
                Cells(r1, "e").Value = a4
                Cells(r1, "f").Value = a5
                Cells(r1, "g").Value = a6
                Cells(r1, "h").Value = a7
                Cells(r1, "i").Value = a8
                Cells(r1, "j").Value = a9
                Cells(r1, "k").Value = a10
            
                r15 = r15 + 1
          
              
            Sheets("Database").Select
           
            End If
    Next x
    Sheets("Add").Select
End If
End Sub

Re: Search ออก เเต่ปัญหาติดว่าไม่ออกค่าล่าสุด

Posted: Wed Jul 18, 2018 8:43 pm
by snasui
:D แนบไฟล์ที่เขียน Code มาด้วยพร้อมชี้ให้เห็นว่าถ้าถูกต้องจะได้ค่าเป็นเท่าใด พิจารณาอย่างไรจึงได้ค่าเท่านั้น จะได้เข้าใจตรงกันและสะดวกในการตอบครับ