在列中查找特定单词,然后将相邻的值复制到其他列中

时间:2019-06-26 05:40:31

标签: excel vba

我需要Excel VBA中的帮助

enter image description here

我需要找到一个文本(标题-例如帐户),单词“ Account”的单元格将始终位于C列中 并从相邻的C列复制值并将它们粘贴在同一张纸上到A列 直到C列中的值为止(例如-09:00-09:30直到结束)

列 A B C

    Account Test1
    Group   XXX
    Date    Mon24 Jun, 2019

    09:00-09:30 
    09:30-10:00 
    10:00-10:30 
    10:30-11:00 
    11:00-11:30 
    11:30-12:00 
    12:00-12:30 
    12:30-13:00 
    13:00-13:30 
    17:30-18:00 


    Account Test2
    Group   YYY
    Date    Mon24 Jun, 2019

    09:00-09:30 
    09:30-10:00 
    10:00-10:30 
    10:30-11:00 
    11:00-11:30 
    11:30-12:00 
    12:00-12:30 
    12:30-13:00 
    13:00-13:30 
    17:30-18:00 

2 个答案:

答案 0 :(得分:0)

尝试一下。

Sub ApplyHeader()
    Dim c As Range, Acc$, Grp$

    'Loops through first to last used i column C
    For Each c In Range(Cells(1, 3), Cells(Rows.Count, 3).End(xlUp))

        'Stores value from adjacent cell if it says "Account".
        If c.Value = "Account" Then Acc = c.Offset(, 1).Value

        'Stores value from adjacent cell if it says "Group".
        If c.Value = "Group" Then Grp = c.Offset(, 1).Value

        'Applies stored values in columns to the left if first character is numerical.
        If IsNumeric(Left(c.Value, 1)) Then
            c.Offset(, -2).Value = Acc
            c.Offset(, -1).Value = Grp
        End If
    Next c

    'Removes stored values from "memory".
    Acc = "": Grp = ""
End Sub

答案 1 :(得分:0)

@AsUsual

我找到了d方法->

tooltip: {
    pointFormat: '{point.date:%d-%B}'
}

结束子