將帶有相應鍵的文字清單格式化為電子表格

將帶有相應鍵的文字清單格式化為電子表格

我有一個文字文件,其日期如此排列。

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)

是否有一種函數或方法可以在具有兩列的電子表格中排列數據,例如:

+---------------+-----+
| 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. 否則貼上單元格 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

相關內容