excel - 分组其他列excel后分组消失-无法使用摘要行
问题描述
我正在尝试对 Excel 中的列进行分组。如下面显示的屏幕截图所示,我在第一个屏幕截图中将 C27 分组到 C30。但是,当我转到 E 列并尝试将 E31 分组到 E35 时,它不起作用,并且之前的分组消失了。我怎样才能解决这个问题?我不想添加摘要行,因为没有什么要总结的。
此代码的功能是每隔一列对空白进行分组,例如 C 列中的第 27 到 30 行和 E 列中的第 31 到 25 行
For iColumn = 1 To 11 Step 2
'loop through rows
iStartRow = -999
'from first cell in column
For iRow = wksSupervisor.Cells(1, iColumn).End(xlDown).Row + 1 To wksSupervisor.Cells.SpecialCells(xlCellTypeLastCell).Row
iLastRow = wksSupervisor.Cells(10000, iColumn + 2).End(xlUp).Row
'Check if empty cell has text above
If IsEmpty(wksSupervisor.Cells(iRow, iColumn)) And Not IsEmpty(wksSupervisor.Cells(iRow - 1, iColumn)) Then
'start row of grouping is current row
iStartRow = iRow
End If
'check if empty cell has text below
If IsEmpty(wksSupervisor.Cells(iRow, iColumn)) And Not IsEmpty(wksSupervisor.Cells(iRow + 1, iColumn)) Then
'empty cell
bFoundLastRow = True
iEndRow = iRow
End If
'Check if we have both the start row to group and last row to group
If (bFoundLastRow = True Or iRow = iLastRow) And (iStartRow <> iEndRow) And (iStartRow <> -999) Then
iEndRow = iRow
If IsEmpty(wksSupervisor.Cells(iEndRow, iColumn)) Then
wksSupervisor.Rows(iStartRow & ":" & iEndRow).Group
bFoundLastRow = False
End If
End If
'Create a separate condition grouping 1 row (syntax is different)
If (bFoundLastRow = True Or iRow = iLastRow) And (iStartRow = iEndRow) Then
wksSupervisor.Cells(iRow, iColumn).Select
Selection.Rows.Group
bFoundLastRow = False
End If
Next iRow
Next iColumn
解决方案
推荐阅读
- r - 使用 dplyr 添加基于其他数据框的新列
- python - Python,我正在使用生成器,但它不起作用
- python - Selenium,项目发送做数据库,python
- installation - DbFit 无法在设置页面中连接和查找灯具
- flutter - 颤振不构建aab文件
- arrays - 在 swift 代码中保留 UISearchController 中的选定项目(如 Snapchat/Messenger/Whatsapp)
- bitcoin - 运行 RPC 查询命令时,Electrumx 服务器不显示数据
- java - 将 JDK8 升级到 OpenJKD 11:sun.security.rsa
- angular - 通过 *ngFor,Angular 9 从数组中生成 html 模板中的列表的问题
- python - 如何使用 Flask、Jinja 和 Dataframe 使 bootstrap-table-filter-control 工作