Excel工作表布局: 10表垂直堆叠,每个表之间有一空行。
目标:组&将空白数据行隐藏在10个表中的每个表中(因为不是每个表中的所有行都会返回数据)。
代码:对每个表进行单独的逐行测试。一旦它测试了一个空行的TRUE,它就退出DO循环,并从空行到尾行隐藏该表的其余部分。它移动到下一个表并测试/隐藏此表的空白行.等。直到对所有表进行了测试,并将所有空白行分组/隐藏。
问题:--我希望所有分组都属于一个分组级别。因此,excel工作表左上角的“组级别”将只显示"1,2“作为选项,所有分组同时隐藏/关闭。运行此代码后,将显示8个不同的组级别"1,2,3,4,5,6,7,8“。
如何让我的代码将所有分组放在一个组级别上?
'Group Attribute Rollups
x = linesheet_rollupatt11_row
Do Until x > linesheet_rollupatt125_row
If Cells(x, linesheet_brand_clmn) = "" Then
att1_count = x
Exit Do
End If
x = x + 1
Loop
x = linesheet_rollupatt21_row
Do Until x > linesheet_rollupatt225_row
If Cells(x, linesheet_brand_clmn) = "" Then
att2_count = x
Exit Do
End If
x = x + 1
Loop
x = linesheet_rollupatt31_row
Do Until x > linesheet_rollupatt325_row
If Cells(x, linesheet_brand_clmn) = "" Then
att3_count = x
Exit Do
End If
x = x + 1
Loop
x = linesheet_rollupatt41_row
Do Until x > linesheet_rollupatt425_row
If Cells(x, linesheet_brand_clmn) = "" Then
att4_count = x
Exit Do
End If
x = x + 1
Loop
x = linesheet_rollupatt51_row
Do Until x > linesheet_rollupatt525_row
If Cells(x, linesheet_brand_clmn) = "" Then
att5_count = x
Exit Do
End If
x = x + 1
Loop
x = linesheet_rollupatt61_row
Do Until x > linesheet_rollupatt625_row
If Cells(x, linesheet_brand_clmn) = "" Then
att6_count = x
Exit Do
End If
x = x + 1
Loop
x = linesheet_rollupatt71_row
Do Until x > linesheet_rollupatt725_row
If Cells(x, linesheet_brand_clmn) = "" Then
att7_count = x
Exit Do
End If
x = x + 1
Loop
x = linesheet_rollupatt81_row
Do Until x > linesheet_rollupatt825_row
If Cells(x, linesheet_brand_clmn) = "" Then
att8_count = x
Exit Do
End If
x = x + 1
Loop
x = linesheet_rollupatt91_row
Do Until x > linesheet_rollupatt925_row
If Cells(x, linesheet_brand_clmn) = "" Then
att9_count = x
Exit Do
End If
x = x + 1
Loop
x = linesheet_rollupatt101_row
Do Until x > linesheet_rollupatt1025_row
If Cells(x, linesheet_brand_clmn) = "" Then
att10_count = x
Exit Do
End If
x = x + 1
Loop
x = linesheet_rollupatt111_row
Do Until x > linesheet_rollupatt1125_row
If Cells(x, linesheet_brand_clmn) = "" Then
att11_count = x
Exit Do
End If
x = x + 1
Loop
If Cells(linesheet_rollupatt1header_row, linesheet_vendorname_clmn).Value = "" Then
Rows(linesheet_rollupatt1header_row & ":" & linesheet_rollupatt125_row).Select
Selection.Rows.Group
Else
Rows(att1_count & ":" & linesheet_rollupatt125_row).Select
Selection.Rows.Group
End If
If Cells(linesheet_rollupatt2header_row, linesheet_vendorname_clmn).Value = "" Then
Rows(linesheet_rollupatt2header_row & ":" & linesheet_rollupatt225_row).Select
Selection.Rows.Group
Else
Rows(att2_count & ":" & linesheet_rollupatt225_row).Select
Selection.Rows.Group
End If
If Cells(linesheet_rollupatt3header_row, linesheet_vendorname_clmn).Value = "" Then
Rows(linesheet_rollupatt3header_row & ":" & linesheet_rollupatt225_row).Select
Selection.Rows.Group
Else
Rows(att3_count & ":" & linesheet_rollupatt325_row).Select
Selection.Rows.Group
End If
If Cells(linesheet_rollupatt4header_row, linesheet_vendorname_clmn).Value = "" Then
Rows(linesheet_rollupatt4header_row & ":" & linesheet_rollupatt225_row).Select
Selection.Rows.Group
Else
Rows(att4_count & ":" & linesheet_rollupatt425_row).Select
Selection.Rows.Group
End If
If Cells(linesheet_rollupatt5header_row, linesheet_vendorname_clmn).Value = "" Then
Rows(linesheet_rollupatt5header_row & ":" & linesheet_rollupatt225_row).Select
Selection.Rows.Group
Else
Rows(att5_count & ":" & linesheet_rollupatt525_row).Select
Selection.Rows.Group
End If
If Cells(linesheet_rollupatt6header_row, linesheet_vendorname_clmn).Value = "" Then
Rows(linesheet_rollupatt6header_row & ":" & linesheet_rollupatt225_row).Select
Selection.Rows.Group
Else
Rows(att6_count & ":" & linesheet_rollupatt625_row).Select
Selection.Rows.Group
End If
If Cells(linesheet_rollupatt7header_row, linesheet_vendorname_clmn).Value = "" Then
Rows(linesheet_rollupatt7header_row & ":" & linesheet_rollupatt225_row).Select
Selection.Rows.Group
Else
Rows(att7_count & ":" & linesheet_rollupatt725_row).Select
Selection.Rows.Group
End If
If Cells(linesheet_rollupatt8header_row, linesheet_vendorname_clmn).Value = "" Then
Rows(linesheet_rollupatt8header_row & ":" & linesheet_rollupatt225_row).Select
Selection.Rows.Group
Else
Rows(att8_count & ":" & linesheet_rollupatt825_row).Select
Selection.Rows.Group
End If
If Cells(linesheet_rollupatt9header_row, linesheet_vendorname_clmn).Value = "" Then
Rows(linesheet_rollupatt9header_row & ":" & linesheet_rollupatt225_row).Select
Selection.Rows.Group
Else
Rows(att9_count & ":" & linesheet_rollupatt925_row).Select
Selection.Rows.Group
End If
If Cells(linesheet_rollupatt10header_row, linesheet_vendorname_clmn).Value = "" Then
Rows(linesheet_rollupatt10header_row & ":" & linesheet_rollupatt225_row).Select
Selection.Rows.Group
Else
Rows(att10_count & ":" & linesheet_rollupatt1025_row).Select
Selection.Rows.Group
End If
If Cells(linesheet_rollupatt11header_row, linesheet_vendorname_clmn).Value = "" Then
Rows(linesheet_rollupatt11header_row & ":" & linesheet_rollupatt225_row).Select
Selection.Rows.Group
Else
Rows(att11_count & ":" & linesheet_rollupatt1125_row).Select
Selection.Rows.Group
End If
发布于 2016-02-27 04:16:12
这很可能是因为您的分组重叠。假设所有数据都在一个列中,而且表之间只有一个空白行,那么您应该开始分组,低一行或高一行结束分组。
另外,考虑避免选择(通过.Select,然后是Selection.Rows.Group)。有关示例,请参见下面的代码。
若要结束更高一行的分组,请更改
Rows(linesheet_rollupatt1header_row & ":" & linesheet_rollupatt125_row).Select
Selection.Rows.Group
以及类似的线条
Rows(linesheet_rollupatt1header_row & ":" & linesheet_rollupatt125_row - 1).Group
或者,为了在后面开始分组行,在每个起始行中添加一个"+ 1“。
Rows(linesheet_rollupatt1header_row + 1 & ":" & linesheet_rollupatt125_row).Group
或
Rows(att2_count + 1 & ":" & linesheet_rollupatt225_row).Group
https://stackoverflow.com/questions/35664233
复制相似问题