Page 2 of 2

Re: ต้องการค้าหาข้อมูลที่ตรงกันค่ะ

Posted: Thu Mar 14, 2019 8:56 pm
by snasui
:D หมายถึงเมื่อวางข้อมูลไป 35 บรรทัดลแล้วให้เว้นว่าง 1 บรรทัดและเป็นเช่นนี้ไปเรื่อย ๆ หรือว่าต้องการให้เป็นแบบไหน กรุณาอธิบายพร้อมยกตัวอย่างประกอบจะได้เข้าใจตรงกันครับ

Re: ต้องการค้าหาข้อมูลที่ตรงกันค่ะ

Posted: Thu Mar 14, 2019 10:04 pm
by monthikan
snasui wrote: Thu Mar 14, 2019 8:56 pm :D หมายถึงเมื่อวางข้อมูลไป 35 บรรทัดลแล้วให้เว้นว่าง 1 บรรทัดและเป็นเช่นนี้ไปเรื่อย ๆ หรือว่าต้องการให้เป็นแบบไหน กรุณาอธิบายพร้อมยกตัวอย่างประกอบจะได้เข้าใจตรงกันครับ
ค่ะ คือ ข้อมูลที่ขึ้นอยู่ตอนนี้มันขึ้นเป็นหน้าเดียวยาวๆจนหมดข้อมูล ตาม Sheeta(4) ค่ะ ข้อมูลมันเกินฟอร์มตารางที่วางไว้ค่ะ
คือ อยากให้หลังจากที่ Run แล้วต้องการวางข้อมูลแค่ B6 ถึง B35 ค่ะ แล้วถ้าข้อมูลที่ Run อยู่ยังมีค่าที่ตรงกันอยู่ให้ไปขึ้นบรรทัดที่ C47 แทนค่ะ ตามSheets(3) ค่ะ

Code: Select all

Sub ReportRetriev()
    Dim j As Integer
    Dim c, rng As Range
        On Error Resume Next
       Set rng = Sheets(2).Range("a6:a" & Sheets(2).Range("a" & Rows.Count).End(xlUp).Row)
            For Each c In rng
            With Sheets(4)
                j = .Range("e" & .Rows.Count).End(xlUp).Row + 1
                    If c.Value = .Cells(3, 9) Then
                        .Cells(j, 3).Value = c.Offset(, 2).Value
                        .Cells(j, 4).Value = c.Offset(, 3).Value
                        .Cells(j, 5).Value = c.Offset(, 5).Value
                        .Cells(j, 6).Value = c.Offset(, 6).Value
                        .Cells(j, 7).Value = c.Offset(, 1).Value
                        .Cells(j, 8).Value = c.Offset(, 7).Value
                        .Cells(j, 9).Value = c.Offset(, 9).Value
                    End If
                End With
            Next c
End Sub

Re: ต้องการค้าหาข้อมูลที่ตรงกันค่ะ

Posted: Thu Mar 14, 2019 10:12 pm
by puriwutpokin
ปรับเป็น

Code: Select all

Sub SReportRetriev()
    Dim j As Integer
    Dim l As Long
    Dim c, rng As Range
        On Error Resume Next
       Set rng = Sheets(2).Range("a6:a" & Sheets(2).Range("a" & Rows.Count).End(xlUp).Row)
            For Each c In rng
            With Sheets(3)
                j = .Range("e" & .Rows.Count).End(xlUp).Row + 1
                    If c.Value = .Cells(3, 9) Then
                        .Cells(j, 3).Value = c.Offset(, 2).Value
                        .Cells(j, 4).Value = c.Offset(, 3).Value
                        .Cells(j, 5).Value = c.Offset(, 5).Value
                        .Cells(j, 6).Value = c.Offset(, 6).Value
                        .Cells(j, 7).Value = c.Offset(, 1).Value
                        .Cells(j, 8).Value = c.Offset(, 7).Value
                        .Cells(j, 9).Value = c.Offset(, 9).Value
                        If j = 35 Then
                       j = j + 6
                        .Cells(j, 3).Value = c.Offset(, 2).Value
                        .Cells(j, 4).Value = c.Offset(, 3).Value
                        .Cells(j, 5).Value = c.Offset(, 5).Value
                        .Cells(j, 6).Value = c.Offset(, 6).Value
                        .Cells(j, 7).Value = c.Offset(, 1).Value
                        .Cells(j, 8).Value = c.Offset(, 7).Value
                        .Cells(j, 9).Value = c.Offset(, 9).Value
      
                       End If
                    End If
                End With
            Next c
              
 '       With Sheets(3)

     '       l = .Range("C35" & .Rows.Count).End(xlUp).Row + 1
       
    '        .Range("C41" & l).Select
     '   End With

End Sub

Re: ต้องการค้าหาข้อมูลที่ตรงกันค่ะ

Posted: Thu Mar 14, 2019 10:30 pm
by monthikan
ขอบคุณค่ะอาจารย์ :D :D

Re: ต้องการค้าหาข้อมูลที่ตรงกันค่ะ

Posted: Thu Mar 14, 2019 10:36 pm
by snasui
:D อีกตัวอย่างครับ

ข้อมูลจะวางในชีตลำดับที่ 3

Code: Select all

Dim j As Integer, k As Integer
Dim c As Range, rng As Range
On Error Resume Next
Set rng = Sheets(2).Range("a6:a" & Sheets(2) _
    .Range("a" & Rows.Count).End(xlUp).Row)
j = 5
For Each c In rng
    With Sheets(3)
        If k = 30 Then
            j = j + 12
            k = 0
        Else
            j = j + 1
        End If
        If c.Value = .Cells(3, 9) Then
            .Cells(j, 3).Value = c.Offset(, 2).Value
            .Cells(j, 4).Value = c.Offset(, 3).Value
            .Cells(j, 5).Value = c.Offset(, 5).Value
            .Cells(j, 6).Value = c.Offset(, 6).Value
            .Cells(j, 7).Value = c.Offset(, 1).Value
            .Cells(j, 8).Value = c.Offset(, 7).Value
            .Cells(j, 9).Value = c.Offset(, 9).Value
            k = k + 1
        End If
    End With
Next c

Re: ต้องการค้าหาข้อมูลที่ตรงกันค่ะ

Posted: Thu Mar 14, 2019 11:01 pm
by puriwutpokin
ของอาจารย์คนควนถูกต้องครับ ที่ผมทำไปยังไม่ถูกครับ เพราะมันจะซ้ำ แต่
ของอาจารย์ ต้องแก้ตรงนี้หรือเปล่าครับ มันจะได้ลงตามตารางครับ
จาก

Code: Select all

j = j + 12
เป็น

Code: Select all

j = j + 6

Re: ต้องการค้าหาข้อมูลที่ตรงกันค่ะ

Posted: Thu Mar 14, 2019 11:04 pm
by snasui
:D Code ตามโพสต์ #25 มันจะวางตรงตำแหน่งของแบบฟอร์มในชีตลำดับที่ 3 ลองทดสอบกับไฟล์แนบในโพสต์ #22 ดูครับ

Re: ต้องการค้าหาข้อมูลที่ตรงกันค่ะ

Posted: Thu Mar 14, 2019 11:10 pm
by puriwutpokin
snasui wrote: Thu Mar 14, 2019 11:04 pm :D Code ตามโพสต์ #25 มันจะวางตรงตำแหน่งของแบบฟอร์มในชีตลำดับที่ 3 ลองทดสอบกับไฟล์แนบในโพสต์ #22 ดูครับ
:D :thup: คนไฟล์จริงๆครับ ขอโทษครับ ใช้ไฟล์เก่า :cp: :cp: :cp:

Re: ต้องการค้าหาข้อมูลที่ตรงกันค่ะ

Posted: Mon Mar 18, 2019 5:13 pm
by monthikan
snasui wrote: Thu Mar 14, 2019 10:36 pm :D อีกตัวอย่างครับ

ข้อมูลจะวางในชีตลำดับที่ 3

Code: Select all

Dim j As Integer, k As Integer
Dim c As Range, rng As Range
On Error Resume Next
Set rng = Sheets(2).Range("a6:a" & Sheets(2) _
    .Range("a" & Rows.Count).End(xlUp).Row)
j = 5
For Each c In rng
    With Sheets(3)
        If k = 30 Then
            j = j + 12
            k = 0
        Else
            j = j + 1
        End If
        If c.Value = .Cells(3, 9) Then
            .Cells(j, 3).Value = c.Offset(, 2).Value
            .Cells(j, 4).Value = c.Offset(, 3).Value
            .Cells(j, 5).Value = c.Offset(, 5).Value
            .Cells(j, 6).Value = c.Offset(, 6).Value
            .Cells(j, 7).Value = c.Offset(, 1).Value
            .Cells(j, 8).Value = c.Offset(, 7).Value
            .Cells(j, 9).Value = c.Offset(, 9).Value
            k = k + 1
        End If
    End With
Next c
ขอบคุณค่ะอาจารย์ :D