首页 > 解决方案 > 如何在空白行之间对单元格行进行分组

问题描述

所以我有一个包含不同值(无重复)的列的工作表,它们之间的空白行从第 13 行开始。

我需要分别对 D 列和 E 列中的值进行分组。E 列中的值在下一个值之前由两个空白行分隔,C 列中的值在下一个值之前由一个空白行分隔。

我认为我需要追求的代码逻辑应该类似于 Group cell E13 down 只要在空白行之前有一个值,跳过两个空白行然后冲洗并重复直到 E 列的最后一行。

除了我只跳过一行之外,我将对 D 列使用相同的逻辑。

D列中的值已经可以合并..不确定这是否会影响分组

Dim startrow as long
Dim grouplastrow as long
Dim startgroup as long
Dim blank as long

Startrow = 12
grouplastrow = .cells(rows.count,5).End(xlUp).row ‘finds last row in column E
startgroup = startrow + 1
I = startrow + 1  to grouplastrow ‘means the starting row starts at 13 and ends right at the last row with value, right?)

if cells(i,5)<> "" then 'if this cell has a value then...
'how do i say this is to start the range i want to group until cells(i,5)
'need to make it so that i either skip two rows or i begin the range again at the first cell with value....
range(.cells).group 'this will represent the range i'm grouping before the blank rows and loop until the last row
next i 

标签: excelvba

解决方案


推荐阅读