Sub 降序加编号() Dim sr, sr2 As Range, th%, ch As Range, ch2 As Range Do sr = Application.Max([a:a]) Set sr2 = Range("a:a").Find(sr) If sr2 Is Nothing Then Exit Do Set ch = Cells(Rows.Count, 2).End(xlUp)(2, 1) sr2.Cut ch Set ch2 = Cells(Rows.Count, 2).End(xlUp) If sr2.Value = ch2(0, 1).Value Then ch2(1, 2) = ch2(0, 2) + 1 Else ch2(1, 2) = 1 End If Loop Until sr2 Is Nothing End Sub
用两个函数就搞定了 Sub Count_() Dim r As Long, i As Long, rng_count As Long r = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row For i = 2 To r rng_count = Application.CountIf(Range("a2:a" & i), Cells(i, 1)) Cells(i, 2) = Application.Text(Cells(i, 1), "[dbnum1]") & "枚" & rng_count Next End Sub