読者です 読者をやめる 読者になる 読者になる

半角カナだけを全角にする


Sub ZenToHan()

Dim i As Integer
Dim myLetter As String
Dim myStr As String
Dim myCell As Range

For Each myCell In ActiveSheet.UsedRange
myStr = myCell.Value
i = 1
Do While (i <= Len(myStr))
myLetter = Mid(myStr, i, 1)
Select Case Asc(myLetter)
Case 167 To 181, 197 To 201, 207 To 223
myStr = Left(myStr, i - 1) & StrConv(myLetter, vbWide) _
& Mid(myStr, i + 1)
Case 182 To 196, 202 To 206
If (i < Len(myStr)) Then
Select Case Asc(Mid(myStr, i + 1, 1))
Case 222 To 223
myStr = Left(myStr, i - 1) & _
StrConv(Mid(myStr, i, 2), vbWide) & _
Mid(myStr, i + 2)
Case Else
myStr = Left(myStr, i - 1) & StrConv(myLetter, vbWide) & _
Mid(myStr, i + 1)
End Select
Else
myStr = Left(myStr, i - 1) & StrConv(myLetter, vbWide) & _
Mid(myStr, i + 1)
End If
End Select
i = i + 1
Loop
myCell.Value = myStr
Next

End Sub