2017-06-16 51 views
-1

隨着裁判: - 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.

回答

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

+0

雖然反應是迅速而確實的方式工作,有一個問題。運行腳本時僅執行第一部分,並將組減號放在單詞上方。這可以看看。 –

+0

你能不能顯示輸出的截圖? – Maddy

+0

我試圖把它的截圖放在問題中 - 但發現很難做到。 –