问题描述
我有一个 excel 文件,其中 B1 到 B500 列(可能会有所不同)填充了数字.例如:
I have an excel file which has column B1 to B500 (may vary) filled with numbers. For example:

我需要输出如下:

到目前为止我有这么多代码:
I have this much code till now:
Sub Max()
Dim i As Long, j As Long
Dim cl As Excel.Range
i = 1
j = 1
For i = sheet.UsedRange.Rows.Count To 1 Step -1
cl = sheet.Cells(i, 2) '## Examine the cell in Column B
If xl.WorksheetFunction.CountIf(sheet.Range("B:B"), cl.Value) > 1 Then
cl.Value = sheet.Cells(j, 3).value 'copy to Column C
End If
j = j + 1
Next i
End Sub
此代码的作用是在 B 列中查找重复项并从该列中删除其他条目.在 C 列中没有写任何内容.我希望 B 列最后没有被编辑.这里也搞不清楚如何实现排序.
What this code does is to find duplicates in column B and remove other entries from the column. Nothing gets written in column C. I want the column B to be unedited at the end. Also cannot figure out how to achieve the sorting here.
请帮忙.
推荐答案
好吧,如果你想的话,你也可以使用公式:
Well, you could use formulas if you want too:
使用数组公式非常重要(编辑完单元格后按Ctrl+Shift+Enter),我的Excel是西班牙语版本,所以你只需要更改:- IF SI- CONTAR.SI by COUNT.IF
It is very important to use array formulas (Ctrl+Shift+Enter when done editing the cell), my Excel is an Spanish Version, so you just need to change: - SI by IF - CONTAR.SI by COUNT.IF
我想到了这个解决方案,考虑了 冒泡排序算法.我希望这对你有用.
I came up with this solution thinking about the bubble sort algorithm. I hope this will be useful for you.
这篇关于使用 VB.net 按最大出现次数对 excel 列的值进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!