|
▼初投稿 さん:
ループはなくせないんですが、Parseメソッドに与えるパターンを
無理やり(?)正規表現で作成してみました。
Sub Test2()
Dim reg As Object
Dim s As String
Dim w As Variant
Dim i As Long
s = Range("A1").Value
Set reg = CreateObject("VBScript.RegExp")
reg.Pattern = "(.{1})"
reg.Global = True
s = reg.Replace(s, "$1 ")
w = Split(s)
ReDim Preserve w(LBound(w) To UBound(w) - 1)
For i = LBound(w) To UBound(w)
If LenB(StrConv(w(i), vbFromUnicode)) = 2 Then
w(i) = 2
Else
w(i) = 1
End If
Next
s = Join(w, "")
reg.Pattern = "(2+)"
s = reg.Replace(s, "[$1]")
s = Replace(s, "2", "x")
s = Replace(s, "1", "[x]")
Range("A1").Parse s, Range("A1")
End Sub
|
|