LoginSignup
2
2

More than 5 years have passed since last update.

セル内の行(改行)それぞれに処理を行う関数

Last updated at Posted at 2016-04-04

セル内改行を含むものをfor eachで回すための関数
ググっても出なかったので備忘録

instrの方が早そうだけど、処理する情報量が少ないのでこれでいいかなと、、

Function lines_to_collection_in_cell(text As String) As Collection '入力されたテキストを行ごとにcollectionに格納

    Dim lines As New Collection

    line_start_position = 1

    For i = 1 To Len(text)
        If Mid(text, i, 1) = vbLf Then
            lines.Add Item:=Mid(text, line_start_position, i - line_start_position)
            line_start_position = i + 1
        End If

        If i = Len(text) Then
            lines.Add Item:=Mid(text, line_start_position, i - line_start_position)
        End If

    Next i

    set lines_to_collection_in_cell = lines
End Function
2
2
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
2
2