|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test0()
- Dim ar, dict As Object
- Dim i As Long, num As Long
- Set dict = CreateObject("Scripting.Dictionary")
- ar = Range("A1").CurrentRegion.Resize(, 4).Value
- For i = 2 To UBound(ar)
- ar(i, 4) = ""
- If ar(i, 1) <> ar(i - 1, 1) Or ar(i, 2) = "重要" Then
- num = num + 1
- ar(i, 4) = num
- If Not dict.Exists(ar(i, 1)) Then dict.Add ar(i, 1), num
- Else
- ar(i, 4) = dict(ar(i, 1))
- End If
- Next
- Range("A1").Resize(UBound(ar), UBound(ar, 2)) = ar
- Set dict = Nothing
- Beep
- End Sub
复制代码 |
|