|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 qy1219no2 于 2015-3-10 12:35 编辑
不使用字典的代码(没学会字典前,我也经常对字典犯怵,只好用下面的办法解决,不过,如果数据量多的话,还是建议用字典,这样运算速度会提高不少)- Sub objDic()
- Dim sj(), nRow%, i%, k%, cBj$, r As Range, cAdd$
- nRow = [a65536].End(xlUp).Row
- If nRow < 2 Then Exit Sub
- arr = [a2].Resize(nRow - 1, 2)
- ReDim sj(nRow - 2, 1): k = -1
- For i = 1 To nRow - 1
- If InStr(cBj, arr(i, 1)) = 0 Then
- cBj = cBj & arr(i, 1) & ","
- k = k + 1
- sj(k, 0) = arr(i, 1)
- Set r = [a:a].Find(arr(i, 1), , , 1)
- If Not r Is Nothing Then
- cAdd = r.Address
- Do
- sj(k, 1) = sj(k, 1) & r.Offset(, 1) & ","
- Set r = [a:a].FindNext(r)
- Loop While Not r Is Nothing And r.Address <> cAdd
- If sj(k, 1) <> "" Then sj(k, 1) = Left(sj(k, 1), Len(sj(k, 1)) - 1)
- End If
- End If
- Next
- [d2].Resize(nRow - 1, 2) = sj
- End Sub
复制代码 |
|