Re: ต้องการค้าหาข้อมูลที่ตรงกันค่ะ
Posted: Thu Mar 14, 2019 8:56 pm
คลังคำตอบแห่งความรู้จากคนไทย เพื่อโลกที่ต้องการเข้าใจในสิ่งเล็ก ๆ อย่างลึกซึ้ง
https://snasui.com/
ค่ะ คือ ข้อมูลที่ขึ้นอยู่ตอนนี้มันขึ้นเป็นหน้าเดียวยาวๆจนหมดข้อมูล ตาม Sheeta(4) ค่ะ ข้อมูลมันเกินฟอร์มตารางที่วางไว้ค่ะsnasui wrote: Thu Mar 14, 2019 8:56 pmหมายถึงเมื่อวางข้อมูลไป 35 บรรทัดลแล้วให้เว้นว่าง 1 บรรทัดและเป็นเช่นนี้ไปเรื่อย ๆ หรือว่าต้องการให้เป็นแบบไหน กรุณาอธิบายพร้อมยกตัวอย่างประกอบจะได้เข้าใจตรงกันครับ
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 SubCode: 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 SubCode: 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
Code: Select all
j = j + 12Code: Select all
j = j + 6snasui wrote: Thu Mar 14, 2019 11:04 pmCode ตามโพสต์ #25 มันจะวางตรงตำแหน่งของแบบฟอร์มในชีตลำดับที่ 3 ลองทดสอบกับไฟล์แนบในโพสต์ #22 ดูครับ
ขอบคุณค่ะอาจารย์snasui wrote: Thu Mar 14, 2019 10:36 pmอีกตัวอย่างครับ
ข้อมูลจะวางในชีตลำดับที่ 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