Page 1 of 1

สวัสดีครับพอดีมีคำถามเกี่ยวกับ code ค้นหา

Posted: Thu Oct 19, 2017 3:18 pm
by yahomyfriend
พอดีผมทำ code เกี่ยวกับการทำการค้นหาแล้วทีนี้ผมอยากให้มันค้นหาได้มากกว่าที่ผมทำได้ตอนนี้แบบพิมพ์ keyword อะไรก็ได้ถ้ามันมีก็ให้มันแสดงแต่ทีนี้ผมทำได้แค่ อย่างเดียวคือ Jobname ผมขอแนวทางจากพี่ๆได้ไหมครับ

Code: Select all

Private Sub txtSearch_Change()
Dim I As Long
Dim b As Long
Dim RRng As Range
Dim RRow As Long
Dim LastRow As Long
Me.ListBox1.Clear


LastRow = Worksheets("Data").Cells(Sheets("Data").Rows.Count, "A").End(xlUp).Row + 1

'Row Listbox
b = 0

For I = 2 To LastRow
    
    Set RRng = Range("A" & I).find(txtSearch.Text, LookIn:=xlValues, LookAt:=xlPart)
    
    If Not RRng Is Nothing Then
        RRow = RRng.Row
        
        If b = 0 Then
            ListBox1.AddItem
            
            ListBox1.List(0, 0) = "Job Name"
            ListBox1.List(0, 1) = "Location"
            ListBox1.List(0, 2) = "User"
            ListBox1.List(0, 3) = "Tel No."
            ListBox1.List(0, 4) = "Status"
            ListBox1.List(0, 7) = "Maker"
            b = 1
        End If
        ListBox1.AddItem
        ListBox1.List(b, 0) = Worksheets("Data").Range("A" & I).Value
        ListBox1.List(b, 1) = Worksheets("Data").Range("B" & I).Value
        ListBox1.List(b, 2) = Worksheets("Data").Range("C" & I).Value
        ListBox1.List(b, 3) = Worksheets("Data").Range("D" & I).Value
        ListBox1.List(b, 4) = Worksheets("Data").Range("E" & I).Value
        ListBox1.List(b, 5) = Worksheets("Data").Range("F" & I).Value
        
        b = b + 1
        
'Me.ListBox1.AddItem Data.Cells(i, 1).Value
'Me.ListBox1.List(ListBox1.ListCount - 1, 1) = Sheet1.Cells(i, 2).Value
    End If
    Next I
End Sub

Re: สวัสดีครับพอดีมีคำถามเกี่ยวกับ code ค้นหา

Posted: Thu Oct 19, 2017 8:35 pm
by snasui
:D ตัวอย่างการค้นหาด้วย VBA ทุกคอลัมน์ ดูได้จาก wordpress/search-vba/ ลองประยุกต์ใช้ดูครับ

Re: สวัสดีครับพอดีมีคำถามเกี่ยวกับ code ค้นหา

Posted: Sat Oct 21, 2017 10:18 pm
by kio2002
อาจารย์พอจะมีตัวอย่าง code vba ที่ใช้ค้นหาคำที่ใกล้เคียงกับที่ค้นหาไหมครับ
สินค้าที่ผมบันทึกไว้ สมมุติมีดังนี้
1 ไม้เชิงชาย
2 ไม้พื้น
3 ไม้บันได
เช่น ค้นหาคำว่า "ไม้" ให้นำสินค้าที่มีคำว่าไม้ 1-3 มาแสดงใน toolbox ที่สามารถคลิกเลือก แล้วบันทึกลงใน sheet ได้

Re: สวัสดีครับพอดีมีคำถามเกี่ยวกับ code ค้นหา

Posted: Sat Oct 21, 2017 10:32 pm
by snasui
:D ดู VDO ในลิงก์ที่ผมแนบไว้ด้านบนครับ