|
不知道是不是你想要的
- Sub main()
- Dim wb As Workbook
- Dim sht As Worksheet
- Set dic = CreateObject("Scripting.Dictionary")
- Set wb = Application.ThisWorkbook
- Set sht = wb.Worksheets(1)
- With sht
- erow = .Cells(.Rows.Count, 1).End(xlUp).Row
- r = 0
- For i = 1 To erow
- ar = Split(.Cells(i, 1).Value, "/")
- For Each e In ar
- If e <> "" Then
- a = RegReplace(e, "\d", "#")
- If dic.exists(a) = False Then
- dic(a) = Int(65536 * Rnd)
- Debug.Print dic(a)
- End If
- r = r + 1
- .Cells(r, 3).Value = e
- .Cells(r, 3).Interior.Color = dic(a)
- End If
- Next
- Next i
- End With
- End Sub
- Function RegReplace(ByVal text As String, ByVal pat As String, Optional rep As String = "") As String
- Dim reg, ms, m
- Set reg = CreateObject("VBScript.RegExp")
- With reg
- .Global = True
- .IgnoreCase = True
- .Pattern = pat
- End With
- RegReplace = reg.Replace(text, rep)
- Set reg = Nothing
- End Function
复制代码 |
|