2017-01-18 48 views
0

我希望有人也许能够帮助让我在这里...折叠某些群体(不是全部)使用VBA

我有一个巨大的名单,并正在使用分组来组织它:

enter image description here

正如您所看到的,我有一个主要组行,其中包含许多产品。然后,有些产品会在该部分下面分组。

我想要的是折叠只显示产品的所有配件组。下面的代码将展开未扩展的组,我不希望这样。

shtOTP.Outline.ShowLevels RowLevels:=4 
shtOTP.Outline.ShowLevels RowLevels:=3 
shtOTP.Outline.ShowLevels RowLevels:=2 
ActiveWindow.ScrollRow = shtOTP.Range("A3").row 'Go to top of sheet 

我试图寻找到.Outline.Parent.Outline.SummaryRow功能,但据我可以告诉他们不识别该组的“父”。

我可以做一个循环以下:

For i = 3 To getLastRow 
    Dim nextRow As Integer 
    nextRow = shtOTP.Rows(i+1).row 
    If nextRow = ParentRow And i.EntireRow.Hidden = False Then 
     'Collapse the group below the product 
    End If 
Next 

但是......

如何做我确定如果nextRow是parentRow?

如何我是否应该折叠?

回答

0

我能拿出一个短宏来做到这一点:

Application.ScreenUpdating = False 

    Dim row As Range 

    For i = 3 To getLastRow 
     Set row = shtOTP.Range("A" & i) 

     If row.EntireRow.Hidden = True Then     
      'Do nothing 
     ElseIf row.Value = "SM" Then      'Minor Sub-model row, needs to be collapse 
      If shtOTP.Rows(i).EntireRow.ShowDetail = True Then 
       shtOTP.Rows(i).EntireRow.ShowDetail = False 
      End If 
     End If 
    Next 

Application.ScreenUpdating = True 

我放在“SM”,在该行的A单元的配件,以便更好地识别它们。