将带有相应键的文本列表格式化为电子表格

将带有相应键的文本列表格式化为电子表格

我有一个文本文件,其中的日期排列如下。

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. 切割细胞
  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

相关内容