使用颜色自动创建组

时间:2017-06-16 09:52:01

标签: excel excel-vba juniper vba

参考: - Automating group creation

我有一个类似的问题 - 我将juniper代码导入excel并希望将其分组 - 请参阅截图。

问题是在原始问题中identifier.,在这种情况下,identifier将是任何不以空格开头的行,并且分组会是所有行,直到下一行,然后开始没有空格。 然后有一些额外的“喜欢”着色线,以便该组很容易看到。

另外,我认为这是原来的问题 - 然后小组需要向下扩展 - 而不是向上扩展。

希望这是有道理的。

Screenshot of example before and after here

screenshot of when script has run - notice - second section not grouped and start of group is above - would like it to be on the same line.

1 个答案:

答案 0 :(得分:0)

试试这个

    Sub sda()
    lLastRow = Cells(Rows.Count, 1).End(xlUp).Row
    Set Rng = Range("A1:A" & lLastRow)
    For Each cell In Rng
    LResult = Left(cell.Value, 1)
    If LResult = " " Or IsEmpty(cell.Value) Then GoTo nxtCl:
    startRownum = cell.Row
    Set rng2 = Range("A" & startRownum + 1 & ":A" & lLastRow)
    For Each cll In rng2
    LResult = Left(cll.Value, 1)
    If LResult = " " Or IsEmpty(cell.Value) Then GoTo nxtCl2:
    endRownum = cll.Row
    Rows(startRownum + 1 & ":" & endRownum - 1).Group
    Exit For
    nxtCl2:
    Next
    nxtCl:
    Next
    End Sub

enter image description here

相关问题