0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【VBA】文字列をカンマ区切りで配列に変換

Last updated at Posted at 2020-06-03
Sub aaa()
    myRange = Range("A1", "A2")
    arr = WorksheetFunction.Transpose(myRange)
    For i = 1 To UBound(arr)
        '''
        spli = Split(arr(i), ",")
        Data = "0x06, 0x46, 0x05, 0x22, 0x03, "
        s = Data
        For c = 0 To UBound(spli)
            s = Replace(s, (spli(c) + ","), "")  '"[値],"を削除
            s = Replace(s, "  ", " ") '"  "(半角スペースが2つ)なら1つに変換
            If InStr(s, " ") = 1 Then s = Right(s, Len(s) - 1) '先頭が" "(半角スペース)なら削除
        Next
        If InStrRev(s, " ") - Len(s) = 0 Then s = Left(s, Len(s) - 1) '末尾が","(カンマ)なら削除
        If InStrRev(s, ",") - Len(s) = 0 Then s = Left(s, Len(s) - 1) '末尾が" "(半角スペース)なら削除
        Debug.Print (s)
        '''
    Next
End Sub

参考
http://officetanaka.net/excel/vba/tips/tips62.htm
https://kosapi.com/post-2305/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?