By พายุทอร์นาโด ในวันพุธที่ 19 มกราคม 2022
โพสต์ใน Excel
ตอบกลับ 1
การกดไลค์ 0
เข้าชม 8.8K
โหวต 0
ถึงทุกค ณ

ถ้าฉันมีแถวที่ n (จำนวนมาก) ฉันต้องการนับรายการที่ซ้ำกันทุกๆ 10 เซลล์ ตัวอย่างเช่น

ตัวอย่างเช่นฉันมีชุดต่อไปนี้
2
1
1
1
1
1
1
3
2

ฉันต้องนับรายการที่ซ้ำกัน (คำนึงถึงสำเนาแรก) แต่ละ 3 เซลล์เช่นผลลัพธ์ควรเป็น
2
1
3


ข้อเสนอแนะใด ๆ
ขอบคุณล่วงหน้า. 
สวัสดี mtornado,

ในการลบค่าที่ซ้ำกันทุกๆ 10 เซลล์โปรดทำดังนี้:

  1. ในเวิร์กชีตของคุณ ให้กด อื่น ๆ + F11จากนั้นคลิก สิ่งที่ใส่เข้าไป > โมดูล;
  2. คัดลอกโค้ดด้านล่าง และวางลงในกล่องโมดูล
  3. ข่าวประชา F5 ในการรันโค้ด คุณจะเห็น a Kutools สำหรับ Excel ไดอะล็อกที่แสดงด้านล่าง:
  4.   ไดอะล็อก.png

  5. กลับไปที่เวิร์กชีตของคุณแล้วเลือกช่วง จากนั้นคลิกที่ OK ปุ่มบนกล่องโต้ตอบ


Sub RemoveDuplicatesValue_10()

Dim xSltRg, xCells, xRg As Range
Dim xStartRg, xEndRg As Range
Dim xSInt, xCount, xRntInt, xNumInt, xF As Integer
On Error Resume Next

xSInt = 10
Set xSltRg = Application.InputBox("Select range:", "Kutools for Excel", , , , , , 8)
If xSltRg Is Nothing Then Exit Sub
Set xSltRg = Application.Intersect(ActiveSheet.UsedRange, xSltRg)
Set xSltRg = Application.Union(xSltRg, xSltRg.Item(1))
xCount = xSltRg.Count
xNumInt = Int(xCount / xSInt)
xRntInt = 0
xRntInt = xCount Mod xSInt
For xF = 1 To xNumInt
Set xStartRg = xSltRg.Item(((xF - 1) * xSInt + 1))
Set xEndRg = xSltRg.Item(xF * xSInt)
Set xCells = xSltRg.Worksheet.Range(xStartRg.AddressLocal & ":" & xEndRg.AddressLocal)
For xInt = xCells.Count To 1 Step -1
Set xRg = xCells.Item(xInt)
If WorksheetFunction.CountIf(xCells, xRg.Value) > 1 Then
xRg.Value = ""
End If
Next
Next
If xRntInt > 0 Then
Set xStartRg = xSltRg.Item(xNumInt * xSInt + 1)
Set xEndRg = xSltRg.Item(xCount)
Set xCells = xSltRg.Worksheet.Range(xStartRg.AddressLocal & ":" & xEndRg.AddressLocal)
For xInt = xCells.Count To 1 Step -1
Set xRg = xCells.Item(xInt)
If WorksheetFunction.CountIf(xCells, xRg.Value) > 1 Then
xRg.Value = ""
End If
Next
End If

End Sub


โปรดทราบว่าหากต้องการลบค่าที่ซ้ำกันทุก N เซลล์ ให้เปลี่ยน 10 ในโค้ดเป็น N

อแมนดา
·
2 ปีที่ผ่านมา
·
0 ชอบ
·
0 คะแนน
·
0 คอมเมนต์
·
ดูโพสต์แบบเต็ม