|
练习练习
- Sub test() '替换
- Set d = CreateObject("Scripting.dictionary")
- c = Cells(4, Columns.Count).End(1).Column
- r = Cells(Rows.Count, 1).End(3).Row
- For i = 5 To r
- For j = 3 To c
- s = Cells(i, j).Value
- s1 = Left(s, 1)
- If s1 <> "" And s1 <> "自" Then
- a = Split(s, vbLf)
- If a(1) = "" Then
- If d.exists(s1) Then
- Cells(i, j) = Cells(i, j) & d(s1)
- Else
- a(1) = s1 & 0
- Cells(i, j) = Join(a, vbLf)
- End If
- Else
- d(s1) = a(1)
- Rows(i).Replace What:=s1 & 0, Replacement:=a(1)
- End If
- End If
- Next
- Next
- End Sub
- Sub test2() '数组
- Set d = CreateObject("Scripting.dictionary")
- c = Cells(4, Columns.Count).End(1).Column
- r = Cells(Rows.Count, 1).End(3).Row
- arr = Range("c5", Cells(r, c))
- For i = 1 To UBound(arr)
- For j = 1 To UBound(arr, 2)
- s = arr(i, j)
- s1 = Left(s, 1)
- If s1 <> "" And s1 <> "自" Then
- a = Split(s, vbLf)
- s2 = d(s1)
- If a(1) = "" Then
- If Left(s2, 1) = "," Or s2 = "" Then
- d(s1) = s2 & "," & j
- ElseIf Len(s2) > 1 Then
- arr(i, j) = arr(i, j) & s2
- End If
- Else
- If Left(s2, 1) = "," Then
- b = Split(s2, ",")
- For k = 1 To UBound(b)
- arr(i, b(k)) = arr(i, b(k)) & a(1)
- Next
- End If
- d(s1) = a(1)
- End If
- End If
- Next
- d.RemoveAll
- Next
- Range("c5", Cells(r, c)) = arr
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|