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]
เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง).Apply
ครับCode: Select all
ActiveWorkbook.Worksheets("test").sort.SortFields.Clear
ActiveWorkbook.Worksheets("test").sort.SortFields.Add Key:=Range("k6:K17"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("test").sort
.SetRange Range("J5:K16")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Code: Select all
Dim rall As Range, icount As Long
Dim r1 As Range, r2 As Range
Dim c As New Collection, item As Variant
With ActiveSheet
Set rall = Union(.[b3:e5], .[b19:e24])
.Range("j6:j1000,o6:o1000").ClearContents
For Each r1 In rall
icount = 0
For Each r2 In rall
If r1.Value = r2.Value Then
icount = icount + 1
End If
Next r2
On Error Resume Next
If icount > 1 Then
c.Add CStr(r1.Value), CStr(r1.Value)
End If
On Error GoTo 0
Next r1
For Each item In c
If CLng(item) <= .[j2] Then
.Range("j" & .Rows.Count).End(xlUp) _
.Offset(1, 0).Value = CLng(item)
Else
.Range("o" & .Rows.Count).End(xlUp) _
.Offset(1, 0).Value = CLng(item)
End If
Next item
End With
หมายถึง ถ้าผิดพลาดก็ให้ Run ต่อเนื่องไป ไม่ต้องแสดง Error ที่เขียนไว้เช่นนี้จำเป็นต้องทราบนะครับว่าบรรทัดต่อจากบรรทัดนี้จะเกิด Error ลักษณะใด ไม่ใช่ว่าใช้ในทุกกรณีchom_poona wrote:On Error Resume Next ---> คืออะไรค่ะ
คำสั่งนี้ใช้แปลงchom_poona wrote:If CLng(item) <= .[j2] Then --> CLng คืออะไรค่ะ ตัวแปรหรือ คำสั่งค่ะ
item
ให้มี Variable Type เป็น Longในเครื่องผมไม่เกิด Error ครับchom_poona wrote:เอา code มาใส่แล้ว ลอง run ดู
error ค่ะ ตรง with activesheet
chom_poona wrote:ตัวแปร Collection คืออะไรหรอค่ะ
แปลอย่างง่าย Collection เปรียบเหมือนกล่อง เป็นตัวแปรที่ใช้เก็บตัวแปรอื่น เหมือน Workbooks ที่มีหลาย Workbook เหมือน Worksheets ที่มีหลาย Worksheet เช่นนี้เป็นต้นchom_poona wrote:c.Add CStr(r1.Value), CStr(r1.Value) คำสั่งนี้ คืออะไรหรอค่ะ
c.Add CStr(r1.Value), CStr(r1.Value)
คือการเพิ่มค่าสมาชิกให้กับ Collection ที่ชื่อ c ครับ