1

我在 excel 中获得了一个输入文件,该文件仅沿“M2”列向下移动。把输入文件长这样:

ru_utime     0.060              
ru_stime     0.140              
ru_maxrss    0                          
ru_ixrss     0                          
ru_ismrss    0                          
ru_idrss     0                          
ru_isrss     0                          
ru_minflt    4124                       
ru_majflt    0                          
ru_nswap     0                          
ru_inblock   0                          
ru_oublock   0                          
ru_msgsnd    0                          
ru_msgrcv    0                          
ru_nsignals  0                          
ru_nvcsw     47174                      
ru_nivcsw    4347                       
==================================================

然后它以相同的格式重复大约 1000 次以上

正如您所看到的,它在同一列中有两位信息,然后下一组由 === 分隔我想要做的是忽略每一位的标题并获取右侧的信息并将它们移动到下面的不同列彼此。

我想要做的是阅读文件并将所有信息放在像 ru_utime : 0.060这样的不同列下

所以所有数据都在“M2”中,我想获取相应的标题信息并将它们移动到每个标题的 S2、T2、U2 中,然后当它点击时 ======= 为它下面的下一个做. 如果这对任何人都有意义,我将非常感谢您的帮助。

目的是通过单击按钮自动移动,谢谢

添加:

Sub incorperate()
sn = Split(Join(Application.Transpose(Sheets("sheet2").Cells(1).CurrentRegion.Columns(1)), "|"), String(62, "=") & "|")
With Sheets("sheet1").Cells(1).CurrentRegion
st = .Rows(1).Offset(.Rows.Count).Resize(UBound(sn) + 1)
End With

For j = 0 To UBound(sn)
sq = Split(sn(j), "|")
For jj = 0 To UBound(sq) - 1
  st(j + 1, jj + 1) = Split(sq(jj))(UBound(Split(Trim(sq(jj)))))
Next
Next

Sheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(UBound(st), UBound(st, 2)) = st
End Sub
4

1 回答 1

1
Sub move()
Dim x, y(), i&, j&, k&, s

x = Range("S1", Cells(1, Columns.Count).End(xlToLeft)).Value
With CreateObject("Scripting.Dictionary")
    .CompareMode = 1
    For i = 1 To UBound(x, 2)
        .Item(x(1, i)) = i
    Next i

    x = Application.Trim(Range("M2", Cells(Rows.Count, "M").End(xlUp)).Value)
    ReDim y(1 To UBound(x), 1 To .Count): j = 1

    For i = 1 To UBound(x)
        If InStr(x(i, 1), "==") = 0 Then
            s = Split(x(i, 1))
            If .Exists(s(0)) Then
                k = .Item(s(0)): y(j, k) = s(UBound(s))
            End If
        Else
            j = j + 1
        End If
    Next i
End With

[s2].Resize(j, UBound(y, 2)).Value = y()
End Sub
于 2012-04-16T11:50:38.823 回答