EXCEL TOOLS
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
[code]
และปิดด้วย [/code]
ตัวอย่างเช่น [code]dim r as range[/code]
เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง)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
tigerwit wrote: Mon Mar 10, 2025 10:38 pm หากมีรายการเกิน 30 รายการ
ให้เอาไปแค่ 30 รายการต้องปรับโค๊ดอย่างไรครับ
Code: Select all
'Other code
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
Application.CutCopyMode = False
If i >= 30 Then Exit For
End If
'Other code
Code: Select all
Dim i As Long, j As Integer
'Other code
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
Application.CutCopyMode = False
j = j + 1
If j >= 30 Then Exit For
End If
'Other code