用近似的或不引起混淆的字符把那些字符替换掉:
Sub zz()
Dim d, d1, ar, br, bt
Set d = CreateObject("Scripting.Dictionary")
Set d1 = CreateObject("Scripting.Dictionary")
bt = Array("材料类别", "物料代码", "物料名称", "规格型号", "单位", "是否贴片", "是否通用", "材料存储要求", "代码申请人", "品牌信息", "备注", "状态", "是否禁选")
zf1 = Array(":", "\", "/", "?", "*", "[", "]")
zf2 = Array("∶", "|", "_", "?", "※", "[", "]")
Application.ScreenUpdating = False
ar = Sheet1.Range("A1").CurrentRegion
For Each sh In Sheets
d1(sh.Name) = ""
Next
For i = 2 To UBound(ar)
d(ar(i, 3)) = d(ar(i, 3)) & "," & i
Next
For Each k In d.keys
For y = 0 To UBound(zf1)
If InStr(k, zf1(y)) Then
kk = Replace(k, zf1(y), zf2(y))
End If
Next
If kk = "" Then kk = k
ReDim br(1 To UBound(ar), 1 To 13)
m = 0: s = Split(Mid(d(k), 2), ",")
For i = 0 To UBound(s)
m = m + 1: x = Val(s(i))
For j = 1 To 5
br(m, j) = ar(x, j)
Next
For j = 6 To 12
br(m, j) = ar(x, j + 6)
Next
br(m, 13) = ar(x, 26)
Next
If Not d1.exists(kk) Then
Sheets.Add after:=Sheets(Sheets.Count)
With ActiveSheet
.[a1].Resize(1, UBound(bt) + 1) = bt: .[a2].Resize(m, 13) = br
.Columns("A:M").EntireColumn.AutoFit
.UsedRange.Borders.LineStyle = xlContinuous: .Name = kk: kk = ""
End With
Else
With Sheets(kk)
lr = .[a65536].End(3).Row + 1: .Cells(lr, 1).Resize(m, 13) = br
.UsedRange.Borders.LineStyle = xlContinuous
End With
End If
Next
Application.ScreenUpdating = True
End Sub
|