対応するキーを使用してテキストリストをスプレッドシートにフォーマットします

対応するキーを使用してテキストリストをスプレッドシートにフォーマットします

日付がこのように並べられたテキスト ファイルがあります。

name1
2010-01-02 (i)
2010-05-07 (i)
2010-06-12 (i)
name2
2010-01-02 (i)
2010-05-07 (i)
2010-06-12 (i)
name3
2011-01-05 (i)
2011-05-05 (i)
2011-06-14 (i)

次のような 2 列のスプレッドシートでデータを整理する関数または方法はありますか?

+---------------+-----+
| 2010-01-02 (i)|name1|
| 2010-05-07 (i)|name1|
| 2010-06-12 (i)|name1|  
| 2010-01-02 (i)|name2|
| 2010-05-07 (i)|name2|
| 2010-06-12 (i)|name2|
| 2011-01-05 (i)|name3|
| 2011-05-05 (i)|name3|
| 2011-06-14 (i)|name3|
+---------------+-----+

つまり、アイテムを分類して数えることができるということですか?

編集
列Aをループできるマクロを書く必要があると思います

  1. !もし "()"
  2. セルをカット
  3. それ以外の場合はセルBを貼り付けます

答え1

データが Sheet1 の列 A にあると仮定すると、次のようになります。

Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Option Explicit
Sub rearrange()
    Dim elements As Integer, rowIndex As Integer, i As Integer
    Dim Name As String
'   LO Basic additions
    Dim Doc As Object
    Dim Sheet As Object
    dim cell as object
    Doc = ThisComponent
    Sheet = Doc.Sheets.getByName("Sheet1")

    Cell = Sheet.getCellRangeByName("D1")

    Cell.formula = "=COUNTA(A1:A104586)"

    elements = cell.value
    rowIndex = 1
    For i = 1 To elements
        If Right(Range("A" & i), 3) <> "(i)" Then
            Name = Range("A" & i)
        Else
            Range("B" & rowIndex) = Name
            Range("C" & rowIndex) = Range("A" & i)
            rowIndex = rowIndex + 1
        End If
    Next
End Sub

関連情報