สอบถาม CodeVB Show ดึงข้อมูลมาแสดงตามเงื่อนไข
Posted: Mon Mar 10, 2025 10:38 pm
จากไฟล์ที่แนบมา
ต้องการดึงข้อมูลจากชีท Product ไปวางที่ชีท BaiBake โดยเลือกจากเลขที่ชุดเบิก
และมีเงื่อนไขว่า หากมีรายการเกิน 30 รายการ
ให้เอาไปแค่ 30 รายการต้องปรับโค๊ดอย่างไรครับ
Code: Select all
Sub Recall()
Dim i As Long
With Worksheets("BaiBake")
If Application.CountIfs(Worksheets("Product").Range("D:D"), Worksheets("BaiBake").Range("M10")) = 0 Then
MsgBox ("ไม่มีเลขที่สั่งซื้อนี้ กรุณาตรวจสอบ")
Range("M10").ClearContents
Range("M10").Select
Exit Sub
End If
End With
With Worksheets("BaiBake")
If Range("M10").Value = "" Then
Range("M10").Select
MsgBox ("คุณยังไม่กรอกเลขที่บันทึก !!!")
Exit Sub
End If
' If Range("K1").Value > 30 Then
' MsgBox ("เบิกได้ครั้งหนึ่ง ไม่เกิน 30 รายการ กรุณาเลือกใหม่")
' Range("M10").Select
' Exit Sub
' End If
End With
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Range("E8:F37").ClearContents
For i = 2 To 5000
If Sheets("Product").Range("D" & i).Value = Sheets("BaiBake").Range("M10") Then
Sheets("Product").Range("G" & i).Copy
Sheets("BaiBake").Range("E" & Rows.Count).End(xlUp).Offset(1, 0) _
.PasteSpecial xlPasteValues
Sheets("Product").Range("J" & i).Copy
Sheets("BaiBake").Range("F" & Rows.Count).End(xlUp).Offset(1, 0) _
.PasteSpecial xlPasteValues
End If
Next i
Range("M5").Select
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
และมีเงื่อนไขว่า หากมีรายการเกิน 30 รายการ
ให้เอาไปแค่ 30 รายการต้องปรับโค๊ดอย่างไรครับ