ユーザー定義関数の見本をつくってください。
convert(”あ1いうえお”)
結果
あ 1 い う え お
仕様:一文字毎に半角スペースを入れる
文字の中に全角数字があれば半角にする
渡ってくるものは文字列のみです。
こんな感じでどうでしょう。
全角数値の判定部分はもっとスマートな方法があると思いますが・・・、最低でもCase文にすべきですかね。
Function convert(moji As String) As String
Dim i, tmp
convert = ””
For i = 1 To Len(moji)
tmp = Mid(moji, i, 1)
If tmp = ”0” Then tmp = ”0”
If tmp = ”1” Then tmp = ”1”
If tmp = ”2” Then tmp = ”2”
If tmp = ”3” Then tmp = ”3”
If tmp = ”4” Then tmp = ”4”
If tmp = ”5” Then tmp = ”5”
If tmp = ”6” Then tmp = ”6”
If tmp = ”7” Then tmp = ”7”
If tmp = ”8” Then tmp = ”8”
If tmp = ”9” Then tmp = ”9”
If i = 1 Then
convert = tmp
Else
convert = convert & ” ” & tmp
End If
Next i
End Function
http://www.hondarer-soft.com/cx/pukiwiki/pukiwiki.php?Memo%2F200...
[hondarer-soft] to [cx20.main.jp]
あまりテストしていませんが、こんな感じでしょうか。
StrConv() という関数が VBA に用意されているので、それを利用すると簡単に変換ができます。
Sub Main()
Dim strData As String
Dim strConverted As String
strData = ”あ1いうえお”
strConverted = Convert(strData)
Debug.Print strConverted
End Sub
Function Convert(ByVal strSrc As String) As String
Dim strResult As String
Dim c As String
Dim i As Integer
For i = 1 To Len(strSrc)
c = Mid(strSrc, i, 1)
strResult = strResult & StrConv(c, vbNarrow) & ” ”
Next
Convert = strResult
End Function
ありがとうございます。ぐるぐる回してスペースを入れていく、っていうのがどうやってかけるのかと思っていました。