|
こんばんは。
正規表現を使用した別解です。
但し、例は、アクティブシートに対しての全角--半角変換です。
標準モジュールに、
'==================================================
Dim regEx, Match, Matches
'==================================================
Sub main()
Dim rng As Range
Application.ScreenUpdating = False
Set regEx = CreateObject("VBScript.RegExp")
For Each rng In ActiveSheet.UsedRange
With rng
.Value = alph_cnv_narrow(.Value)
End With
Next
Set regEx = Nothing
Application.ScreenUpdating = True
End Sub
'=========================================================
Function alph_cnv_narrow(strng)
regEx.Pattern = "([A-Z])+"
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(strng)
alph_cnv_narrow = strng
If Matches.Count > 0 Then
For Each Match In Matches
regEx.Pattern = Match.Value
regEx.IgnoreCase = False
alph_cnv_narrow = regEx.Replace(alph_cnv_narrow, StrConv(Match.Value, vbNarrow))
Next
End If
End Function
|
|