2016-12-02 127 views
1

我有一個Excel這樣的:有沒有辦法自動分組行?

Name  DOC  STATUS 
John  ID   OK 
John  ADRESS  Incomplete 
John  SURNAME Missing 
Lara  ID   OK 
Lara  ADRESS  Missing 
Lara  SURNAME Missing 
Rony  ID   OK 
Rony  ADRESS  OK 
Rony  SURNAME OK 

的想法是,該名重演,因爲每個DOC的3倍。有沒有辦法自動分組行?像,每3行一組?

+0

一樣,組怎麼樣?有邊界?合併單元格?在單行中? –

+1

可以使用'範圍( 「A」 &I& 「:A」 &I + 2).Rows.Group',它將組中的一個''For'環一起3行i' –

+0

@TimWilkinson喜歡選擇行,進入數據 - >組 –

回答

1

如果將Group 3行,因爲你的數據在連續行,您將獲得1個巨大的組合在一起行的範圍。

如果你想組的方式,只有第一個值是可見的,而其他2摺疊,那麼你實際上需要集團僅第二和第三行。

代碼

Option Explicit 

Sub GroupEveryNRows() 

Dim i As Long, LastRow As Long 

' modify "Sheet1" to your sheet's name 
With Sheets("Sheet1") 
    ' find last row with data in Column A 
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 

    ' loop from 2nd row till last row with data (assuming the first row has headers) 
    For i = 2 To LastRow Step 3 
     Range("A" & i + 1 & ":A" & i + 2).Rows.Group 
    Next i 
End With 

End Sub 
+0

它的工作!謝謝! –