自动化组创建颜色

问题描述:

随着裁判: - Automating group creation自动化组创建颜色

我有一个类似的问题 - 由此我进口桧代码到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.

试试这个

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

+0

虽然反应是迅速而确实的方式工作,有一个问题。运行脚本时仅执行第一部分,并将组减号放在单词上方。这可以看看。 –

+0

你能不能显示输出的截图? – Maddy

+0

我试图把它的截图放在问题中 - 但发现很难做到。 –