|
原帖由 waterman927 于 2010-9-4 13:43 发表
已经上传附件
想要返回在一列中重复出现的数字所在的行号
已经用公式实现一个数字出现两次的情况,但是不知道能否实现同一数字出现多于三次的情况
请各位大仙帮忙看看,用公式或者VBA都行
多谢多谢!!
78440 ...
你的情况:同一数字会出现多少次呢?
只要单元格放得下,出现多少次都可以实现,就是不知道太多了电脑会不会爆掉... 电脑也会有怨言的:你玩我呢!hehe- Sub My_test()
- Dim i, rng, arr
- Dim d As Object
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- rng = Sheet1.Range("j1:j" & Sheet1.[j65536].End(xlUp).Row)
- ReDim arr(2 To UBound(rng))
- For i = 2 To UBound(rng)
- If rng(i, 1) <> "" Then
- If Not d.exists(rng(i, 1)) And rng(i, 1) <> "" Then
- d(rng(i, 1)) = i
- Else
- d(rng(i, 1)) = d(rng(i, 1)) & " " & i
- d1(rng(i, 1)) = d(rng(i, 1))
- End If
- End If
- Next i
- For i = 2 To UBound(rng)
- If d1.exists(rng(i, 1)) Then arr(i) = Replace(Application.WorksheetFunction.Trim(Replace(d1(rng(i, 1)), i, "")), " ", ",")
- Next i
- Sheet1.Range("k2").Resize(UBound(arr) - 1, 1) = Application.Transpose(arr)
- Set d = Nothing
- Set d1 = Nothing
- Erase arr
- End Sub
复制代码 详见附件
供参考 |
|